42 lines
820 B
C++
42 lines
820 B
C++
|
/**
|
|||
|
* File: stack.cpp
|
|||
|
* Created Time: 2022-11-28
|
|||
|
* Author: qualifier1024 (2539244001@qq.com)
|
|||
|
*/
|
|||
|
|
|||
|
#include "../utils/common.hpp"
|
|||
|
|
|||
|
/* Driver Code */
|
|||
|
int main() {
|
|||
|
/* <20><>ʼ<EFBFBD><CABC>ջ */
|
|||
|
stack<int> stack;
|
|||
|
|
|||
|
/* Ԫ<><D4AA><EFBFBD><EFBFBD>ջ */
|
|||
|
stack.push(1);
|
|||
|
stack.push(3);
|
|||
|
stack.push(2);
|
|||
|
stack.push(5);
|
|||
|
stack.push(4);
|
|||
|
cout << "ջ stack = ";
|
|||
|
printStack(stack);
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB>Ԫ<EFBFBD><D4AA> */
|
|||
|
int top = stack.top();
|
|||
|
cout << "ջ<EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD> top = " << top << endl;
|
|||
|
|
|||
|
/* Ԫ<>س<EFBFBD>ջ */
|
|||
|
stack.pop(); // <20><EFBFBD><DEB7><EFBFBD>ֵ
|
|||
|
cout << "<EFBFBD><EFBFBD>ջԪ<EFBFBD><EFBFBD> pop = " << top << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD> stack = ";
|
|||
|
printStack(stack);
|
|||
|
|
|||
|
/* <20><>ȡջ<C8A1>ij<EFBFBD><C4B3><EFBFBD> */
|
|||
|
int size = stack.size();
|
|||
|
cout << "ջ<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD> size = " << size << endl;
|
|||
|
|
|||
|
/* <20>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA> */
|
|||
|
bool empty = stack.empty();
|
|||
|
cout << "ջ<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD> = " << empty << endl;
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|