#include<iostream>
//帶頭結(jié)點(diǎn)頭插法實(shí)現(xiàn)鏈棧
using namespace std;
typedef struct SNode{
int data;
struct SNode *next;
}SNode,*LinkStack;
void InitStack(LinkStack &S){
S=new SNode;
S->next=NULL;
}
void DestroyStack(LinkStack &S){
S->next=NULL;
delete(S);
}
void ClearStack(LinkStack &S){
S->next=NULL;
}
bool StackEmpty(LinkStack S){
if(S->next==NULL)
return true;
else
return false;
}
bool Push(LinkStack &S,int e){
SNode *p=new SNode;
if(!p) return false;
p->data=e;
p->next=S->next;
S->next=p;
return true;
}
bool Pop(LinkStack &S,int &e){
if(S->next==NULL)return false;
SNode *p=new SNode;
p=S->next;
e=p->data;
S->next=p->next;
delete(p);
return true;
}
int main(){
LinkStack S;
InitStack(S);
int a,k;
while(cin>>a){
Push(S,a);
}
while(S->next!=NULL){
Pop(S,k);
cout<<k;
}
DestroyStack(S);
return 0;
}
關(guān)于&引用 帶&就是要更改本來的值的話使用甥材,如果只需要顯示則不需要