基本容器c栈

有些题目用栈还是很方便的,比如括号配对的问题,还有船舶进港出港的问题。

c++中有现成的STL可以使用

这里https://blog.csdn.net/liujiuxiaoshitou/article/details/53394888 有通过c语言实现栈的9种方式的代码,可以对栈的内核了解的更加清晰。

c++  中可以使用的模板有

s.push(item); //将item压入栈顶
s.pop(); //删除栈顶的元素,但不会返回
s.top(); //返回栈顶的元素,但不会删除
s.size(); //返回栈中元素的个数
s.empty(); //检查栈是否为空,如果为空返回true,否则返回false 

  这些可以满足大多数基本需要

操作示例:

#include <iostream>

#include <cstdio>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include<cmath>
#include <vector>
#include <stack>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
stack<int>a;
int b,t;
cin>>b;
a.push(b);
cin>>b;
a.push(b);
//a.pop();
cout<<a.top();
return 0;
return 0;

  后面很多需要与栈配合起来使用才能更简便,有蛮多升级操作不大会的,后面弄清楚了会陆续补充的


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值