File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -36,19 +36,23 @@ void show() {
36
36
int main () {
37
37
int ch, x;
38
38
do {
39
+ std::cout << " \n 0. Exit or Ctrl+C" ;
39
40
std::cout << " \n 1. Push" ;
40
41
std::cout << " \n 2. Pop" ;
41
42
std::cout << " \n 3. Print" ;
42
- std::cout << " \n Enter Your Choice : " ;
43
+ std::cout << " \n Enter Your Choice: " ;
43
44
std::cin >> ch;
44
- if (ch == 1 ) {
45
- std::cout << " \n Insert : " ;
46
- std::cin >> x;
47
- push (x);
48
- } else if (ch == 2 ) {
49
- pop ();
50
- } else if (ch == 3 ) {
51
- show ();
45
+ switch (ch){
46
+ case 0 : break ;
47
+ case 1 : std::cout << " \n Insert : " ;
48
+ std::cin >> x;
49
+ push (x);
50
+ break ;
51
+ case 2 : pop ();
52
+ break ;
53
+ case 3 : show ();
54
+ break ;
55
+ default : std::cout << " Invalid option!\n " ; break ;
52
56
}
53
57
} while (ch != 0 );
54
58
You can’t perform that action at this time.
0 commit comments