list.java
来自「模拟操作系统的进程调用」· Java 代码 · 共 86 行
JAVA
86 行
import java.awt.*;
import java.awt.event.*;
import asd.Inform;
class ListNode {
Inform data;
ListNode next;
ListNode( Inform idata , ListNode nextNode )
{
data = idata;
next = nextNode;
}
}
public class List {
private ListNode head;
private ListNode tail;
private String name;
public List( String s )
{
name = s;
head = tail = null;
}
public List()
{
this( "List" );
}
public void insertAtFront( Inform insertItem )
{
if ( isEmpty() )
head = tail = new ListNode( insertItem , null );
else
head = new ListNode( insertItem ,head );
}
public void insertAtBack ( Inform insertItem )
{
if ( isEmpty() )
head = tail = new ListNode( insertItem , null );
else
tail = tail.next = new ListNode( insertItem ,null );
}
public Inform removeFromFront()
{
Inform removeItem = null;
removeItem = head.data;
if ( head.equals(tail) )
head = tail = null;
else
head = head.next;
return removeItem;
}
public Inform Remove ( Inform item )
{
Inform removeItem = null;
if( head.equals(tail ) )
head = tail = null;
else{
ListNode current = head;
while (current.data != item )
current = current.next;
removeItem = current.data;
}
return removeItem;
}
public boolean isEmpty()
{ return head == null;}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?