-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackDemo.java
More file actions
45 lines (38 loc) · 731 Bytes
/
stackDemo.java
File metadata and controls
45 lines (38 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class stack{
int stck[] = new int[10];
int tos;
stack(){
tos=-1;
}
void push(int item){
if(tos==9)
System.out.println("Stack Over flow");
else
stck[++tos]=item;
}
int pop(){
if(tos==-1){
System.out.print("Stack Under flow");
return 0;
}
else
return stck[tos--];
}
}
class stackDemo {
public static void main(String args[]){
stack myStack = new stack();
stack myStack2 = new stack();
for(int i=0;i<11;i++){
myStack.push(i);
System.out.println("King "+i);
}
for(int i=11;i<21;i++)
myStack2.push(i);
for(int i=0;i<11;i++)
System.out.print(myStack.pop()+"\t");
System.out.println();
for(int i=0;i<10;i++)
System.out.print(myStack2.pop()+"\t");
}
}