diff --git a/data_structures/stack_using_linked_list.cpp b/data_structures/stack_using_linked_list.cpp index 202c5c9b6..a87e6efb0 100644 --- a/data_structures/stack_using_linked_list.cpp +++ b/data_structures/stack_using_linked_list.cpp @@ -15,7 +15,7 @@ void push(int x) { } void pop() { - if (top_var == NULL) { + if (top_var == nullptr) { std::cout << "\nUnderflow"; } else { node *t = top_var; @@ -27,14 +27,14 @@ void pop() { void show() { node *t = top_var; - while (t != NULL) { + while (t != nullptr) { std::cout << t->val << "\n"; t = t->next; } } int main() { - int ch, x; + int ch = 0, x = 0; do { std::cout << "\n0. Exit or Ctrl+C"; std::cout << "\n1. Push"; @@ -42,17 +42,23 @@ int main() { std::cout << "\n3. Print"; std::cout << "\nEnter Your Choice: "; std::cin >> ch; - switch(ch){ - case 0: break; - case 1: std::cout << "\nInsert : "; + switch (ch) { + case 0: + break; + case 1: + std::cout << "\nInsert : "; std::cin >> x; push(x); break; - case 2: pop(); + case 2: + pop(); break; - case 3: show(); + case 3: + show(); + break; + default: + std::cout << "Invalid option!\n"; break; - default: std::cout << "Invalid option!\n"; break; } } while (ch != 0);