#include<iostream.h>
class linkstack
{
public :
int data;
linkstack *next;
void inistack (linkstack *top);// 初始化栈
void push(linkstack *top,int x);//压入链栈
void pop(linkstack *top);//删除栈顶元素
int gettop(linkstack *top);//取栈顶元素
bool empty(linkstack *top);//判断栈是否为空
};
void linkstack::inistack(linkstack *top)
{
top->next=NULL;
}
void linkstack::push(linkstack *top,int x)
{
linkstack *s;
s=new linkstack;
s->data=x;
s->next=top->next;
top->next=s;
}
void linkstack::pop(linkstack *top)
{
linkstack *s;
s=top->next;
if(s!=NULL)
{
top->next=s->next;
delete(s);
}
}
int linkstack::gettop(linkstack *top)
{
if(top->next!=NULL)
return top->next->data;
else
return NULL;
}
bool linkstack::empty(linkstack *top)
{
if(top->next=NULL)
return(true);
else
return(false);
}
void main()
{
linkstack *top=new linkstack();//定义并初始化链栈
top->inistack(top);
top->push(top,10);
top->push(top,11);
cout<<top->gettop(top)<<endl;
}