-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackOps.java
83 lines (78 loc) · 2.1 KB
/
StackOps.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// import java.util.Scanner;
// class Stack{
// int top;
// int[] arr = new int[10];
// Stack(){
// top = -1;
// }
// boolean push(int ele){
// if(top == 9){
// System.out.println("Stack overflow!!");
// return false;
// }
// else{
// System.out.println("Enter value");
// int val = ele.nextInt();
// top++;
// arr[top] = val;
// System.out.println("value pushed");
// return true;
// }
// }
// boolean pop(){
// if(top == -1){
// System.out.println("Stack UnderFlow!!");
// return false;
// }
// else{
// top--;
// System.out.println("value popped");
// return true;
// }
// }
// void peek(){
// if(top != -1){
// System.out.println(arr[top]);
// }
// else{
// System.out.println("Stack empty");
// }
// }
// }
// public class StackOps {
// public static void main(String[] args) {
// int choice = 0;
// Scanner sc = new Scanner(System.in);
// Stack s = new Stack();
// while(choice != 4){
// System.out.println("Enter your choice");
// System.out.println("1: Push\n2: Pop\n3: Peek\n4: Exit\n ");
// choice =sc.nextInt();
// switch(choice){
// case 1:
// {
// s.push(sc);
// break;
// }
// case 2:
// {
// s.pop();
// break;
// }
// case 3:
// {
// s.peek();
// break;
// }
// case 4:
// {
// System.exit(0);
// }
// default:
// {
// System.out.println("Invalid choice!!");
// }
// }
// }
// }
// }