Stack in java:
package javaapplication27;import java.util.Stack;
public class TestStack {
public static void main(String[] args) {
Stack obj= new Stack();
Stack obj1= new Stack();
//push some number into the stack
for(int i=0;i<10;i++)
obj.push(i);
for(int i=0;i<20;i++)
obj1.push(i);
//pop those numbers off the stack
System.out.println("Stack in obj");
for(int i=0;i<10;i++)
System.out.println(obj.pop());
System.out.println("Stack in obj1");
for(int i=0;i<10;i++)
System.out.println(obj1.pop());
}
}
OUTPUT:
Stack in obj
9
8
7
6
5
4
3
2
1
0
Stack in obj1
19
18
17
16
15
14
13
12
11
10
0 comments:
Post a Comment