栈和队列简述
栈(LIFO表)
手写栈
int s[10005],tot=0; #define s.push(x) s[++t]=x #define s.pop() tot- #define s.size() tot #define s.top() s[tot]
ps:效率一般高于stl,但只能单纯的放字符和数字,结构体很麻烦。
STL栈
stack <char> s; s.empty(); //判断是否为空(空返回1,非空返回0) s.top(); //访问栈顶元素 s.pop(); //移除栈顶元素 s.push(a[i]); //栈顶写入a[i] s.size(); //返回栈中元素的个数
队列(FIFO表)
手写队列和STL的效率接近,所以还是用STL
queue <int> q; q.front(); //返回队首元素 q.push(x); //将x写入队尾 q.empty(); //判断是否为空 q.size(); //返回队列长度 q.pop(); //删除队首元素 q.back(); //返回队尾元素的值