linklist.java
来自「简单的停车场管理程序,运用了队列与栈来进行车辆存储与停车管理计费」· Java 代码 · 共 86 行
JAVA
86 行
package com.he.java;
import java.io.*;
import com.he.java.*;
public class LinkList
{
public ListNode Header;
public int LinkListLength;
public LinkList()
{
Header = new ListNode (null);
LinkListLength = 0;
}
public void Insert(int i ,ListNode n)
{
ListNode current = Header;
if (i<0||i>LinkListLength)
{
System.out.println("插入标志值超过范围");
return;
}
for (int j = 0;j<i ;j++ )
{
current = current.next;
}
n.next = current.next;
current.next = n;
LinkListLength ++;
}
public void Delete(int i)
{
ListNode current = Header;
if (i<=0||i>LinkListLength)
{
System.out.println("插入标志值超过范围");
return;
}
for (int j = 0;j<i-1 ;j++ )
{
current = current.next;
}
current.next = current.next.next;
LinkListLength --;
}
public int QueryId(ListNode n)
{
ListNode current = Header;
int i=0;
while (current != n)
{
i++;
if (i == 0||i>LinkListLength)
{
System.out.println("插入标志值超过范围");
return 0;
}
}
return i;
}
public ListNode Query(int i)
{
ListNode current = Header;
if (i<=0||i>LinkListLength)
{
System.out.println("查找标志值超过范围");
return null;
}
for (int j = 0;j<i ;j++ )
{
current = current.next;
}
return current;
}
public int getLength()
{
return LinkListLength;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?