用c++编程,声明一个栈类,使用栈操作实现将输入的字符串反向输出的功能。

来源:百度知道 编辑:UC知道 时间:2024/06/04 03:04:01
声明一个栈类,使用栈操作实现将输入的字符串反向输出的功能。

#include<iostream>
#include<stack>
using namespace std;
stack<char> sts;
void main()
{
char i,temp;
for(i=65;i<70;i++)
{
sts.push(i);//进栈
cout<<i<<" ";
}
cout<<endl;
for(i=65;i<70;i++)
{
temp=sts.top();//取栈顶元素
sts.pop();//出栈
cout<<temp<<" ";
}
cout<<endl;
}