#include#includeusing namespace std;typedef struct chain_stack{int data;chain_stack *next;}chain_stack;int push(chain_stack *S,int x){//头插法// chain_stack *head2;chain_stack *node=(chain_shttps://www.3tt.net/?mod=artinfo&aid=427tack *)malloc(sizeof(chain_stack));//创建一个节点,因为是malloc函数分配,分配的空间并不会因为函数运行结束而结束node->data=x;//给节点赋值chain_stack *temp=S->next;node->next=temp;S->next=node;// node->next=temp;return 1;}void print(chain_stack *S){chain_stack *head=S->next;while(head!=NULL){cout<<head->data<<" ";head=head->next;}cout<<endl;}int pop(chain_stack *S){chain_stack *head=S->next;if(head!=NULL){chain_stack *temp=head;int x=head->data;S->next=head->next;free(temp);return x;}return -99999;}int main(){// cout<<"asdasd"<<endl;chain_stack *S=(chain_stack *)malloc(sizeof(chain_stack));S->next=NULL;// cout<<"asd"<<endl;cout<<"push "<<push(S,2)<<endl;cout<<"push "<<push(S,3)<<endl;print(S);cout<<"pop "<<pop(S)<<endl;print(S);return 0;}