MCPcopy Create free account
hub / github.com/Deepali-Srivastava/data-structures-and-algorithms-in-java / Demo

Class Demo

stack/stackArray/Demo.java:10–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import java.util.Scanner;
9
10public class Demo
11{
12 public static void main(String[] args)
13 {
14 int choice,x;
15 Scanner scan = new Scanner(System.in);
16
17 StackA st = new StackA(8);
18
19 while(true)
20 {
21 System.out.println("1.Push an element on the stack");
22 System.out.println("2.Pop an element from the stack");
23 System.out.println("3.Display the top element");
24 System.out.println("4.Display all stack elements");
25 System.out.println("5.Display size of the stack");
26 System.out.println("6.Quit");
27 System.out.println("Enter your choice : ");
28 choice = scan.nextInt();
29
30 if(choice==6)
31 break;
32
33 switch(choice)
34 {
35 case 1 :
36 System.out.println("Enter the element to be pushed : ");
37 x=scan.nextInt();
38 st.push(x);
39 break;
40 case 2:
41 x=st.pop();
42 System.out.println("Popped element is : " + x);
43 break;
44 case 3:
45 System.out.println("Element at the top is : " + st.peek());
46 break;
47 case 4:
48 st.display();
49 break;
50 case 5:
51 System.out.println("Size of stack " + st.size());
52 break;
53 default:
54 System.out.println("Wrong choice");
55 }
56 System.out.println("");
57 }
58 scan.close();
59 }
60}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected