-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
39 lines (34 loc) · 773 Bytes
/
Stack.java
File metadata and controls
39 lines (34 loc) · 773 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
public class Stack {
private int top;
private final int size=100;
private String[] items[];
public Stack() {
items = new String[size][];
top = -1;
}
public boolean isEmpty() {
if (top == -1)
return true;
return false;
}
public boolean isFull() {
if (top == size - 1)
return true;
return false;
}
public void push(String[] x) {
if (isFull())
System.out.println("Stack is full!");
else {
items[++top] = x;
}
}
public String[] pop() {
String[] x=null;
if (isEmpty())
System.out.println("Stack is empty!");
else
x = items[top--];
return x;
}
}