#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; typedef struct LinkStack{ int data; struct LinkStack *next; }; //初始化 void Init_Stack(LinkStack *&S) { S=(LinkStack *)malloc(sizeof(LinkStack)); S->next=NULL; } //进栈 int push_Stack(LinkStack *&S,int e) { LinkStack *s; s=(LinkStack *)malloc(sizeof(LinkStack)); s->data=e; s->next=S->next; S->next=s; } //出栈 int pop_Stack(LinkStack *&S,int &e) { LinkStack *s; if(S->next==NULL) return 0; s=(LinkStack *)malloc(sizeof(LinkStack)); s=S->next; e=s->data; S->next=s->next; free(s); return 1; } //显示 int show_Stack(LinkStack *S) { LinkStack *p; p=S->next; while(p!=NULL) { printf("%d ",p->data); p=p->next; } } int main() { LinkStack *S; Init_Stack(S); push_Stack(S,1); push_Stack(S,2); push_Stack(S,3); show_Stack(S); int a=0; pop_Stack(S,a); show_Stack(S); printf("%d",a); }