www.pudn.com > campusleader.rar > ListQueue.java, change:2012-01-04,size:832b


package GraphPackage; 
public class ListQueue<T> implements QueueInterface<T>{ 
	public class Node 
	{ 
		T data; 
		Node next; 
	public Node(T entry) 
	{ 
		data=entry; 
		next=null; 
	} 
	} 
	private int length; 
	private Node firstNode; 
	private Node lastNode; 
	public boolean isempty() 
	{ 
		if(firstNode==null) 
		return true; 
		else 
		return false; 
	} 
	public void enqueue(T Entry) 
	{ 
		Node Node1=new Node(Entry); 
		if(isempty()) 
		{ 
			firstNode=Node1; 
			lastNode=Node1; 
		} 
		else 
		{ 
			lastNode.next=Node1; 
			lastNode=Node1; 
		} 
	} 
	public void dequeue() 
	{ 
		if(isempty()) 
		System.out.println("The queue is empty"); 
		else 
		firstNode=firstNode.next; 
	} 
	public T getFront() 
	{ 
		return firstNode.data; 
	} 
	public void clear() 
	{ 
		while(!isempty()) 
		{ 
			dequeue(); 
		} 
	} 
}