链栈的实现

typedef int datatype;

typeder struct node{

        datatype data;

        struct node *next;

}linkstack;

linkstack *top;

 

linkstack *setnull(linkstack *top){    //置空

        linkstack *p;

        while(top){

                p=top;

                top=top->next;

                printf("%d",p->data);

                free(p);

        }

        printf("/n");

        return NULL;

}

 

linkstack *push(linkstack *top,int x){      //入栈

        linkstack *p;

        p=(linkstack *)malloc(sizeof(linkstack));

        p->data=x;

        p->next=top;

        return p;

}

 

linkstack *pop(linkstack *top,int *k){         //出栈

        linkstack *p;

        if(top==NULL){

                  printf("Underflow/n");

                  return NULL;

        }

        p=top;

        top=top->next;

        *k=p->data;

        free(p);

        return top;

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(链栈的实现)