definition
private class Node
{
Item item;
Node next;
}
Node first = new Node();
Node second = new Node();
Node third = new Node();
first.item = to;
second.item = be;
third.item = or;
first.next = second;
second.next = third;
operating
Node oldfirst = first;
first = new Node();
first.item = not;
first.next = oldfirst;
first = first.next;
Node oldlast = last;
last = new Node();
last.item = not;
oldlast.next= last;
for(int i=0; i<n;i++)
{ 处理 a[i];}
for(Node x =fisrt,; x!=null; x=x.next)
{ 处理 x.item}
Realization stack
private Node node;(最近添加的元素)
public void push(Item item)
{
Node oldnode = node;
node = new Node ();
node.next = oldnode;
node.item = item;
}
public void pop()
{ Item item = node.item;
node = node.next;
return item;
}
private Node first;
private Node last;
private int N;
public void enqueue(Item item)
{
Node oldlast = last;
last = new Node();
last.item = item;
oldlast.next = null;
if(isEmpty) first = last;
else oldlast.next = last;
N++;
}
public void dequeue()
{
Item item =first.item;
first = first.next;
if(isEmpty) last=null;
N--;
return item;
}