Skip to content

Commit

Permalink
Implements the Stack class
Browse files Browse the repository at this point in the history
  • Loading branch information
theArjun committed Jan 20, 2019
1 parent d44645b commit aa5f4e1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions general/StackDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Scanner;
class StackDemo{
public static void main(String[] args){
Stack st = new Stack();
int data, choice;

while(true){
Scanner in = new Scanner(System.in);c // Takes input from user.
System.out.println("1. Push Element");
System.out.println("2. Pop Element");
System.out.println("3. Display Element");
System.out.println("4. Exit Program");
System.out.print("\nEnter your choice : ");

switch(in.nextInt()){ // Accepts incase of integer input.
case 1:
System.out.println("\nEnter value : ");
data = in.nextInt(); // Receives input from user.
st.push(data);
break;
case 2:
st.pop();
break;
case 3:
st.display();
break;
case 4:
System.exit(0); // Halts the program.
}

}
}
}

0 comments on commit aa5f4e1

Please sign in to comment.