链式队列:使用链表式的节点相连接,所以就不用考虑空间的问题了。
public class QueueList { private class Node{ Node pre,next; int value; } Node front ,rear; int a,b; int size = 0; QueueList(){ front.next = null; front.pre = null; front.value = 0; rear = front; } public void add(Node node){ rear.next = node; node.pre = rear; rear = node; size++; } public Node remove(){ if(front == rear) return null; else{ Node node = new Node(); node = front; front = front.next; size--; return node; } } public int size(){ return size; } }
时间: 2024-11-08 09:05:54