链表<o:p></o:p>
class Node {<o:p></o:p>
Object item; Node next;<o:p></o:p>
Node (Object v) {<o:p></o:p>
item = v; next = null;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
头指针,空尾指针<o:p></o:p>
初始化:head = null;<o:p></o:p>
在x后插入t:<o:p></o:p>
if ( x == null)<o:p></o:p>
{ head = t; head.next = null; }<o:p></o:p>
else { t.next = x.next; x.next = t; }<o:p></o:p>
移走x之后的结点:t = x.next; x.next = t.next;<o:p></o:p>
循环遍历:for ( t = head; t != null; t = t.next )<o:p></o:p>
检查链表是否为空:if ( head == null )<o:p></o:p>
空头结点,空尾指针<o:p></o:p>
初始化:head = new Node(); head.next = null;<o:p></o:p>
在x后插入t:t.next = x.next; x.next = t;<o:p></o:p>
移走x之后的结点:t = x.next; x.next = t.next;<o:p></o:p>
循环遍历:for ( t = head.next; t != null; t = t.next )<o:p></o:p>
检查链表是否为空:if ( head.next == null )<o:p></o:p>
空头结点,空尾结点<o:p></o:p>
初始化:head = new Node(); z = new Node(); head.next = z; z.next = z;<o:p></o:p>
在x后插入t:t.next = x.next; x.next = t;<o:p></o:p>
移走x之后的结点:t = x.next; x.next = t.next;<o:p></o:p>
循环遍历:for ( t = head.next; t != z; t = t.next )<o:p></o:p>
检查链表是否为空:if ( head.next == z )<o:p></o:p>
循环链表<o:p></o:p>
第一次插入:head.next = head;<o:p></o:p>
在x后插入t:t.next = x.next; x.next = t; <o:p></o:p>
移走x之后的结点:t = x.next; x.next = t.next;<o:p></o:p>
循环遍历:t = head; do { t = t.next; } while ( t != head );<o:p></o:p>
检查是否只有一个数据项:if ( head.next == head )<o:p></o:p>
<o:p> </o:p>
堆栈<o:p></o:p>
数组实现<o:p></o:p>
class Stack {<o:p></o:p>
private Object[] s;<o:p></o:p>
private int n;<o:p></o:p>
Stack ( int maxN ) {<o:p></o:p>
s = new Object[maxN]; n = 0;<o:p></o:p>
}<o:p></o:p>
boolean isEmpty() { return ( n == 0 ); }<o:p></o:p>
void push ( Object item ) { s[n++] = item; }<o:p></o:p>
Object pop() {<o:p></o:p>
Object t = s[--n]; s[n] = null; return t;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
链表实现<o:p></o:p>
class Stack {<o:p></o:p>
private Node head;<o:p></o:p>
private class Node {<o:p></o:p>
Object item; Node next;<o:p></o:p>
Node ( Object item, Node next ) {<o:p></o:p>
this.item = item; this.next = next;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
Stack ( Object maxN ) { head = null; }<o:p></o:p>
boolean isEmpty() { return ( head ==null ); }<o:p></o:p>
void push ( Object item ) { head = new Node(item, head); }<o:p></o:p>
Object pop() {<o:p></o:p>
Object v = head.item;<o:p></o:p>
Node t = head.next;<o:p></o:p>
head = t;<o:p></o:p>
return v;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
<o:p> </o:p>
FIFO队列的链表实现<o:p></o:p>
class Queue {<o:p></o:p>
private class Node {<o:p></o:p>
Object item; Node next;<o:p></o:p>
Node ( Object item ) {<o:p></o:p>
this.item = item; this.next = null;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>
Private Node head, tail;<o:p></o:p>
Queue ( Object max ) { head = null; tail = null; }<o:p></o:p>
boolean isEmpty() { return ( head ==null ); }<o:p></o:p>
void put ( Object item ) {<o:p></o:p>
Node t = tail;<o:p></o:p>
tail = new Node(item);<o:p></o:p>
if ( empty() )<o:p></o:p>
head = tail;<o:p></o:p>
else t.next = tail<o:p></o:p>
}<o:p></o:p>
Object get() {<o:p></o:p>
Object v = head.item;<o:p></o:p>
Node t = head.next;<o:p></o:p>
head = t;<o:p></o:p>
return v;<o:p></o:p>
}<o:p></o:p>
}<o:p></o:p>