目录
stack
void stack_constructor(){
stack<int> myStack1;
stack<int> myStack1_2 = stack<int>();
//push入栈
myStack1.push(1);
myStack1.push(2);
//pop出栈
myStack1.pop();
//是否为空
bool isEmpty = myStack1.empty();
cout<<"isEmpty"<<isEmpty<<endl;
//size
int size = (int)myStack1.size();
cout<<"size = "<<size<<endl;
//查看栈顶元素
int top = myStack1.top();
cout<<"top = "<<top<<endl;
}
void stack_pointer(){
//生成一个栈指针
stack<int> *intStack = new stack<int>();
//入栈
intStack->push(1);
cout<<"intStack = "<<intStack<<endl;
//出栈
intStack->pop();
cout<<"intStack = "<<intStack<<endl;
intStack->push(1);
intStack->push(2);
//栈中元素个数
int size = static_cast<int>(intStack->size());
cout<<"size = "<<size<<endl;
//栈是否为空
bool isEmpty = intStack->empty();
cout<<"isEmpty = "<<isEmpty<<endl;
//查看栈顶元素
int topElement = intStack->top();
cout<<"topElement = "<<topElement<<endl;
delete intStack;
}
行者常至,为者常成!