Updated stack_using_array.cpp (#1137)

Added bottom function for getting bottom element from a stack .
This commit is contained in:
pratamjain 2020-10-02 17:52:14 +05:30 committed by GitHub
parent 8ccd66bda3
commit c915f9f3c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);