-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo.java
60 lines (53 loc) · 1.29 KB
/
Demo.java
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
/*
Copyright (C) Deepali Srivastava - All Rights Reserved
This code is part of DSA course available on CourseGalaxy.com
*/
package stackArray;
import java.util.Scanner;
public class Demo
{
public static void main(String[] args)
{
int choice,x;
Scanner scan = new Scanner(System.in);
StackA st = new StackA(8);
while(true)
{
System.out.println("1.Push an element on the stack");
System.out.println("2.Pop an element from the stack");
System.out.println("3.Display the top element");
System.out.println("4.Display all stack elements");
System.out.println("5.Display size of the stack");
System.out.println("6.Quit");
System.out.println("Enter your choice : ");
choice = scan.nextInt();
if(choice==6)
break;
switch(choice)
{
case 1 :
System.out.println("Enter the element to be pushed : ");
x=scan.nextInt();
st.push(x);
break;
case 2:
x=st.pop();
System.out.println("Popped element is : " + x);
break;
case 3:
System.out.println("Element at the top is : " + st.peek());
break;
case 4:
st.display();
break;
case 5:
System.out.println("Size of stack " + st.size());
break;
default:
System.out.println("Wrong choice");
}
System.out.println("");
}
scan.close();
}
}