?? list.java
字號:
import java.awt.*;
import java.awt.event.*;
class ListNode {
String data;
ListNode next;
ListNode( String idata , ListNode nextNode )
{
data = idata;
next = nextNode;
}
}
public class List {
private ListNode head;
private ListNode tail;
private String name;
private int size;
public List( String s )
{
name = s;
head = tail = null;
size = 0;
}
public List()
{
this( "List" );
}
public void insertAtFront( String insertItem ) //在鏈表頭插入結點
{
if ( isEmpty() )
head = tail = new ListNode( insertItem , null );
else
head = new ListNode( insertItem ,head );
size++;
}
public void insertAtBack ( String insertItem ) //在鏈表尾插入結點
{
if ( isEmpty() )
head = tail = new ListNode( insertItem , null );
else
tail = tail.next = new ListNode( insertItem ,null );
size++;
}
public String removeFromFront() //從鏈表頭刪除并返回結點值
{
String removeItem = "";
removeItem = head.data;
if ( head.equals(tail) )
head = tail = null;
else
head = head.next;
size--;
return removeItem;
}
public String remove ( String item )//刪除結點值與參數相等的結點
{
String removeItem = "";
if( head.equals(tail ) )
head = tail = null;
else{
ListNode current = head;
while (current.data != item )
current = current.next;
removeItem = current.data;
}
size--;
return removeItem;
}
public boolean isEmpty()//判斷鏈表是否為空
{ return head == null;}
public int getSize(){ return this.size;}//取得鏈表長度
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -