-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackImplemetation
More file actions
61 lines (44 loc) · 1.14 KB
/
StackImplemetation
File metadata and controls
61 lines (44 loc) · 1.14 KB
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
package com.akash.mishra;
/**
*
* @author Akash
*/
public class StackImplement {
private static final int stackSize = 5;
int[] array = new int[stackSize];
int top = -1;
public void push(int stackElement){
if(top < stackSize-1 )
{
top++;
array[top] = stackElement;
} else {
System.out.println("Stack is overflow");
}
}
public void pop(){
if(top >= 0){
top--;
} else{
System.out.println("Stack is underflow");
}
}
public void printStack(){
if(top >= 0){
for(int i = 0; i <= top; i++){
System.out.println(array[i]);
}
}
}
public static void main(String args[]){
StackImplement si = new StackImplement();
si.push(5);
si.push(6);
si.push(7);
si.push(8);
si.push(9);
si.pop();
si.pop();
si.printStack();
}
}