创建 Node* Create(); 销毁 void Destory(Node* head); 压栈 void Push(int data, node*head); 弹栈 int P

如题所述

struct node{
int data;
node *next;
}
node *create()
{
node Ndata,*head;
head=&Ndata;
head->next=NULL;
return head;
}
void destroy (node *head)
{
node *p,*q;
p=head->next;
for(;p!=NULL;)
{ q=p;
p=next->NULL;
free(q):
}
free(head);
}
void push(int data,node *head)
{ node *p,*q;
p=(node *)malloc(sizeof(struct node));
p->data=data;
q=head->next;
for(;q->next!=NULL;)q=q->next;
p->next=q->next;
q->next=p;
}
int pop(int *data,node *head)
{ node *p;
if(head->next==NULL)
{ printf("栈空\n");
return 0;
}
p=haed->next;
*data=p->data;
head->next=p->next;
free(p);
return 1;
}

温馨提示:答案为网友推荐,仅供参考
相似回答