import java.util.*;
public class StackL {
private LinkedList list = new LinkedList();
public void push(Object v) {
list.addFirst(v);
}
public Object top() {
return list.getFirst();
}
public Object pop() {
return list.removeFirst();
}
public static void main(String[] args) {
StackL stack = new StackL();
int i;
for(i = 0; i < 10; i++)
stack.push(new Integer(i));
System.out.println(stack.top());
System.out.println();
for(i = 0; i < 5; i++)
System.out.println(stack.pop());
}
}
StackL.java output
9
9
8
7
6
5
Tag: Study Code Program Java
No comments:
Post a Comment