Stack: Difference between revisions

Line 6:
 
public class Stack
{
private Node first = null;
public boolean isEmpty {
return (first == null);
}
public Object Pop() {
if (first == null)
throw new Exception("Can't Pop from an empty Stack.");
else {
Object temp = first.Value;
first = first.Next;
return temp;
}
}
public void Push(Object o) {
first = new Node(o, first);
}
class Node {
public Node Next;
public Object Value;
public Node(Object value) {
this(value, null);
}
public Node(Object value, Node next) {
Next = next;
Value = value;
}
}
}
 
'''Compiler:''' JDK 1.5 with Generics
 
// JDK 1.5 with Generics
 
public class Stack<T>
{
private Node first = null;
Anonymous user