mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
feat: Adding switch-case and removing if-else-if (#1727)
* Adding switch-case and removing if-else-if * [feat/fix]: Update Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
parent
7309ef1370
commit
2e6b71e206
@ -36,19 +36,23 @@ void show() {
|
|||||||
int main() {
|
int main() {
|
||||||
int ch, x;
|
int ch, x;
|
||||||
do {
|
do {
|
||||||
|
std::cout << "\n0. Exit or Ctrl+C";
|
||||||
std::cout << "\n1. Push";
|
std::cout << "\n1. Push";
|
||||||
std::cout << "\n2. Pop";
|
std::cout << "\n2. Pop";
|
||||||
std::cout << "\n3. Print";
|
std::cout << "\n3. Print";
|
||||||
std::cout << "\nEnter Your Choice : ";
|
std::cout << "\nEnter Your Choice: ";
|
||||||
std::cin >> ch;
|
std::cin >> ch;
|
||||||
if (ch == 1) {
|
switch(ch){
|
||||||
std::cout << "\nInsert : ";
|
case 0: break;
|
||||||
std::cin >> x;
|
case 1: std::cout << "\nInsert : ";
|
||||||
push(x);
|
std::cin >> x;
|
||||||
} else if (ch == 2) {
|
push(x);
|
||||||
pop();
|
break;
|
||||||
} else if (ch == 3) {
|
case 2: pop();
|
||||||
show();
|
break;
|
||||||
|
case 3: show();
|
||||||
|
break;
|
||||||
|
default: std::cout << "Invalid option!\n"; break;
|
||||||
}
|
}
|
||||||
} while (ch != 0);
|
} while (ch != 0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user