BC 3中如何使用Stack类??

UU码农 2001-04-28 12:37:00
...全文
110 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hello_wyq 2001-04-28
  • 打赏
  • 举报
回复
stack在BCB中是一个模板,在头文件<stack>中。具体的参数如下:
template <class T, class Container = deque<T> >
class stack;
T---表示是你要压栈的数据类型。
容器你可以自己实现,也可以使用默认的系统给你的容器。
#include <stack>
#include <vector>
#include <deque>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
// Make a stack using a vector container
stack<int,vector<int> > s;
// Push a couple of values on the stack
s.push(1);
s.push(2);
cout << s.top() << endl;
// Now pop them off
s.pop();
cout << s.top() << endl;
s.pop();
// Make a stack of strings using a deque
stack<string,deque<string> > ss;

// Push a bunch of strings on then pop them off
int i;
for (i = 0; i < 10; i++)
{
ss.push(string(i+1,'a'));
cout << ss.top() << endl;
}
for (i = 0; i < 10; i++)
{
cout << ss.top() << endl;
ss.pop();
}
return 0;
}
是帮助文件的一个例子,你可以自己去看一看。
cber 2001-04-28
  • 打赏
  • 举报
回复
自己写一个

70,022

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧