From c915f9f3c2e8905ed9f63e1c8a4e518e6a0f5174 Mon Sep 17 00:00:00 2001 From: pratamjain <64429854+pratamjain@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:52:14 +0530 Subject: [PATCH] Updated stack_using_array.cpp (#1137) Added bottom function for getting bottom element from a stack . --- data_structures/stack_using_array.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data_structures/stack_using_array.cpp b/data_structures/stack_using_array.cpp index 0c0813d5e..8483d6ad7 100644 --- a/data_structures/stack_using_array.cpp +++ b/data_structures/stack_using_array.cpp @@ -26,6 +26,7 @@ void show() { } void topmost() { std::cout << "\nTopmost element: " << stack[stack_idx - 1]; } +void bottom() { std::cout << "\nBottom element: " << stack[0]; } // If we need access to first element without using pop command int main() { std::cout << "\nEnter stack_size of stack : "; std::cin >> stack_size; @@ -37,6 +38,7 @@ int main() { std::cout << "\n2. Pop"; std::cout << "\n3. Print"; std::cout << "\n4. Print topmost element:"; + std::cout << "\n5. Print Bottom element:"; std::cout << "\nEnter Your Choice : "; std::cin >> ch; if (ch == 1) { @@ -49,6 +51,8 @@ int main() { show(); } else if (ch == 4) { topmost(); + } else if(ch == 5) { + bottom(); } } while (ch != 0);