-
Notifications
You must be signed in to change notification settings - Fork 0
/
assgn23.java
61 lines (52 loc) · 934 Bytes
/
assgn23.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* stack class */
import java.util.*;
public class assgn23{
public static void main(String[] args){
stack obj = new stack();
obj.pop();
obj.push(2);
obj.push(4);
obj.push(6);
obj.push(7);
obj.push(10);
obj.printstack();
}
}
class stack{
int top=-1;
int max=5;
int[]stack1 = new int[max];
boolean isempty(){
if(top==-1){
return true;
}
else
return false;
}
boolean isfull(){
if(top==max)
return true;
else
return false;
}
void pop(){
if(isempty())
System.out.println("stack is empty you can't pop elements");
else
top--;
}
void push(int num){
if(isfull())
System.out.println("stack is empty you can't insert elements");
else
top++;
stack1[top] = num;
}
void printstack(){
top=0;
while(top!=max){
System.out.println(stack1[top]);
top++;
}
}
}