-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
65 lines (54 loc) · 970 Bytes
/
Main.java
File metadata and controls
65 lines (54 loc) · 970 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
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Arrays;
class Main {
public static void main(String... args){
Stack stack = new Stack();
// stack.push(1);
stack.push(2);
stack.pop();
// stack.push(3);
stack.pop();
stack.push(4);
// System.out.println("Poped" + stack.pop());
System.out.println("Array" + stack.toString());
}
}
class Stack {
private int[] arr = new int[28];
private int index = 0;
boolean isEmpty(){
if(index == 0){
return true;
}
return false;
}
boolean isFull(){
if(index == arr.length){
return true;
}
return false;
}
void push(int newItem){
if(isFull()){
return;
}
arr[index] = newItem;
index++;
}
int pop(){
if(isEmpty()){
return 0;
}
int deletedItem = arr[index-1];
index--;
return deletedItem;
}
int peek(){
if(isEmpty()){
return 0;
}
return arr[index-1];
}
public String toString(){
return Arrays.toString(arr);
}
}