- 栈和队列
栈
- @ 2024-1-19 18:32:47
C++栈 基础代码
#include<iostream>
using namespace std;
int st[1001];
int TOP=0;
void push(int x){ //入栈
++TOP;
st[TOP]=x;
}
void pop(){ //出栈
--TOP;
}
bool empty(){ //判断栈是否为空(空=true 不是空=false)
return TOP==0;
}
int top(){ //访问栈顶
return st[TOP];
}
int main(){
return 0;
}
#include<iostream>
#include<stack>
using namespace std;
int main(){
stack<int>s;
// 栈名.top(); 访问栈顶元素
// 栈名.push(进入元素); 入栈
// 栈名.pop(); 出栈
// 栈名.empty(); 判断栈是否为空(空=true 不是空=false)
// 栈名.size(); 元素的个数
return 0;
}
0 条评论
目前还没有评论...