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


package GraphPackage; 
public class Stack<T> implements StackInterface<T>{ 
	private Node firstNode; 
	public class Node 
	{ 
		T data; 
		Node next; 
	public Node(T newdata) 
	{ 
		data=newdata; 
		//next=node; 
	} 
	} 
	public boolean isempty() 
	{ 
		if(firstNode==null) 
			return true; 
		else 
			return false; 
	} 
	public void push(T newEntry) 
	{ 
		Node Node1=new Node(newEntry); 
		if(isempty()) 
		{ 
			firstNode=Node1; 
		} 
		else 
		{ 
			Node1.next=firstNode; 
			firstNode=Node1; 
		} 
	} 
	public T peek() 
	{ 
		return firstNode.data; 
	} 
	public void pop() 
	{ 
		T a; 
		a=firstNode.data; 
		firstNode=firstNode.next; 
	} 
	public void clear() 
	{ 
		while(!isempty()) 
		{ 
			pop(); 
		} 
	} 
}