-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackx.java
More file actions
51 lines (41 loc) · 925 Bytes
/
Stackx.java
File metadata and controls
51 lines (41 loc) · 925 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
46
47
48
49
50
51
public class Stackx {
public int [] arr;
private int arrSize;
private int top;
public Stackx(int arrSize){
arr = new int[arrSize];
top = -1;
}
public boolean isEmpty(){
return (top == -1);
}
public boolean isFull(){
return (arrSize -1 == top);
}
public void push(int value){
arr[++top] = value;
}
public int pop(){
if(isEmpty()){
System.out.println("Stack is Empty");
return 0;
}
else{
return top--;
}
}
public int peek(){
if(isEmpty()){
System.out.println("Stack is empty");
return 0;
}
else{
return arr[top];
}
}
public void display(int [] arr){
for(int i =0 ; i<arr.length;i++){
System.out.println(i+".Index - "+ arr[i]);
}
}
}