import java.io.*;
class Node<T> {
T value;
Node<T> link;
}
class Stack<T> {
Node<T> top;
public Stack() {
top = null;
}
public void push(T item) {
Node<T> n = new Node<T>();
n.value = item;
n.link = top;
top = n;
}
public T pop() {
T item;
item = top.value;
Node<T> n = top;
n = null;
top = top.link;
return item;
}
public void display() {
Node<T> n = top;
System.out.print("(top)");
while (n != null) {
System.out.print(" ->" + n.value);
n = n.link;
}
System.out.println();
}
}
Comments
Post a Comment