//C++ Stacks(堆栈)成员函数及其操作
#include
#include
#include
using namespace std;
#define LEN_NAME 5
struct node
{
int id;
char name[LEN_NAME];
};
void main()
{
stack a;
node temp[1];
temp[0].id=11;
strcpy(temp[0].name,"aa");
a.push(temp[0]);
temp[0].id=22;
strcpy(temp[0].name,"bb");
a.push(temp[0]);
temp[0].id=33;
strcpy(temp[0].name,"cc");
a.push(temp[0]);
temp[0].id=44;
strcpy(temp[0].name,"dd");
a.push(temp[0]);
cout<<"size:"<<a.size()<<endl;
cout<<"当前栈顶元素:"<<a.top().id<<" "<<a.top().name<<endl;
cout<<"出栈"<<endl;
while(!a.empty())
{
cout<<a.top().id<<" "<<a.top().name<<endl;
a.pop();
}
}
/*------------------------------------------------------
C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,
——也就是说实现了一个先进后出(FILO)的数据结构。
C++ Stacks(堆栈)成员函数
empty() 堆栈为空则返回真
pop() 移除栈顶元素
push() 在栈顶增加元素
size() 返回栈中元素数目
top() 返回栈顶元素
------------------------------------------------------*/
//【www.ok2002.com C++程序设计】
C++中的堆栈(转)
最新推荐文章于 2025-11-30 21:05:18 发布
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
1万+

被折叠的 条评论
为什么被折叠?



