-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (31 loc) · 1.12 KB
/
Main.java
File metadata and controls
40 lines (31 loc) · 1.12 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
public class Main {
public static void main(String[] args) {
TheStack<Integer> stack = new TheStack<Integer>();
stack.push(Integer.valueOf(1));
stack.push(Integer.valueOf(5));
stack.push(Integer.valueOf(34));
stack.push(Integer.valueOf(16));
stack.display();
System.out.println("Top element is " + stack.peek());
try {
System.out.println("The deleted element is " + stack.pop());
System.out.println("The deleted element is " + stack.pop());
System.out.println("The deleted element is " + stack.pop());
System.out.println("The deleted element is " + stack.pop());
System.out.println("The deleted element is " + stack.pop());
} catch (Exception StackEmptyException) {
System.out.println(StackEmptyException.toString());
}
try {
stack.display();
} catch (Exception StackEmptyException) {
System.out.println(StackEmptyException.toString());
}
System.out.println("The size of the stack is: " + stack.getSize());
try {
System.out.println("Top element is " + stack.peek());
} catch (Exception StackEmptyException) {
System.out.println(StackEmptyException.toString());
}
}
}