-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackArrayMenu.java
More file actions
45 lines (40 loc) · 1.6 KB
/
StackArrayMenu.java
File metadata and controls
45 lines (40 loc) · 1.6 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
41
42
43
44
45
import java.util.Scanner;
public class StackArrayMenu {
static Scanner scan = new Scanner(System.in);
public void run() {
String choice = "";
System.out.print("Enter Size: ");
int size = scan.nextInt();
StackArray stkArr = new StackArray(size);
scan.nextLine();
do {
System.out.println("--- Stack Array Menu ---");
System.out.println("[1]: Push\n[2]: Pop\n[3]: Peek\n[4]: Display\n[5]: Quit");
System.out.print("Enter Choice: ");
choice = scan.nextLine().trim();
switch (choice) {
case "1":
System.out.print("Enter value: ");
String val = scan.nextLine();
System.out.println((stkArr.push(val)) ? "Pushed Successfully" : "Stack is Full");
break;
case "2":
System.out.println((stkArr.pop()) ? "Popped Successfully" : "Stack is Empty");
break;
case "3":
String peek = stkArr.peek();
System.out.println((peek == null) ? "Stack is Empty" : "Peek: " + peek);
break;
case "4":
stkArr.display();
break;
case "5":
System.out.println("Exiting Stack Array Menu...");
break;
default:
System.out.println("Invalid Input");
break;
}
} while (!choice.equals("5"));
}
}