#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node *next;
}*sqlist,list;
typedef struct stack{
sqlist top;
}*pstack,stack;
pstack init(){
pstack s=(pstack)malloc(sizeof (stack));
if(s)
s->top=NULL;
return s;
}
void push(pstack s,int data){
sqlist p=(sqlist)malloc(sizeof (list));
if(!p)
printf("内存溢出");
p->data=data;
p->next=s->top;
s->top=p;
}
void pop(pstack s,int *x){
if(s->top==NULL)
printf("栈空");
sqlist p=s->top;
*x=s->top->data;
s->top=s->top->next;
free(p);
printf("--%d",*x);
printf("\n");
}
void pri(pstack s){
sqlist p=s->top;
while (p) {
printf("-->%d",p->data);
p=p->next;
}
};
int main()
{
int x;
pstack s=init();
for(int i=0;i<=10;i++)
push(s,i);
pop(s,&x);
pri(s);
return 0;
}
链栈(非顺序栈)
最新推荐文章于 2024-07-24 16:46:42 发布