-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathStackApp.java
More file actions
42 lines (32 loc) · 752 Bytes
/
StackApp.java
File metadata and controls
42 lines (32 loc) · 752 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
package Java.StacksJava;
public class StackApp {
private long[] stackArray;
private int maxSize;
private int top;
public StackApp(int s) {
maxSize = s;
stackArray = new long[maxSize];
top = -1;
}
public void push(long i) {
stackArray[++top] = i;
}
public long peek() {
return stackArray[top];
}
public long pop() {
return stackArray[top--];
}
public boolean isEmpty() {
return (top == -1);
}
public boolean isFull() {
return (top == maxSize - 1);
}
public void display() {
for (int i = 0; i <= top; i++) {
System.out.print(stackArray[i] + " ");
}
System.out.println("");
}
}