#include <iostream>
using namespace std;
struct Node{ // 定义结构体
char data; // 数据
struct Node *next; // 下一个节点
};
class Stack{ // 类定义
public:
// 默认构造器(定义变量的时候会执行)
Stack(){
head = new Node;
head->next = NULL;
}
~Stack(){
Destory();
}
bool push(char data)
{
Node *newPt = new Node; // 为新数据申请空间
// 若申请失败 返回false
if(!newPt)
return false;
// 为新节点存入数据
newPt->data = data;
// 连接头节点(链表的头插法)
newPt->next = head->next;
head->next = newPt;
return 1;
}// 入栈
char pop() // 出栈
{
char data; // 要弹出的数据
Node *pf; // 要销毁的指针
pf = head->next; // 取第一个数据
if(!pf) // 如若第一个数据为空 则表示栈为空
return 0;
data = pf->data; // 取第一个数据保存进临时变量
head->next = head->next->next; // 节点后移
delete pf; // 删除节点
return data;
}
void Destory() // 销毁
{
Clear(); // 清空所有数据
delete head; // 销毁头节点
}
void Clear() // 清空栈
{
while(isEmpty())
{ // 依次把数据弹出,则变相清空了栈
pop();
}
}
bool isEmpty() // 是否为空
{
if(head->next) // 取第一个节点,不为空表示有数据
return 1;
return 0;
}
private:
Node *head; // 头节点
};
int main()
{
char a[20];
int i=0;
Stack s;
cin>>a;
while(a[i]!=NULL)
{
s.push(a[i]);
i++;
}
while(s.isEmpty())
{
cout<<s.pop ();
}
return 0;
}