You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
933 B
42 lines
933 B
/**
|
|
* File: stack.cpp
|
|
* Created Time: 2022-11-28
|
|
* Author: qualifier1024 (2539244001@qq.com)
|
|
*/
|
|
|
|
#include "../utils/common.hpp"
|
|
|
|
/* Driver Code */
|
|
int main() {
|
|
/* Initialize stack */
|
|
stack<int> stack;
|
|
|
|
/* Element push */
|
|
stack.push(1);
|
|
stack.push(3);
|
|
stack.push(2);
|
|
stack.push(5);
|
|
stack.push(4);
|
|
cout << "Stack stack = ";
|
|
printStack(stack);
|
|
|
|
/* Access stack top element */
|
|
int top = stack.top();
|
|
cout << "Top element of the stack top = " << top << endl;
|
|
|
|
/* Element pop */
|
|
stack.pop(); // No return value
|
|
cout << "Element popped from the stack = " << top << ", after popping";
|
|
printStack(stack);
|
|
|
|
/* Get the length of the stack */
|
|
int size = stack.size();
|
|
cout << "Length of the stack size = " << size << endl;
|
|
|
|
/* Determine if it's empty */
|
|
bool empty = stack.empty();
|
|
cout << "Is the stack empty = " << empty << endl;
|
|
|
|
return 0;
|
|
}
|