#ifndef __LINKSTACK_H__ #define __LINKSTACK_H__
typedef int StackData; typedef struct _node { StackData data; struct _node *next; }Node; typedef struct _linkStack { Node *top; }LinkStack;
int empty(Link* s)
{ if(s == NULL) return FALSE; return s->top == NULL; } int enLink(Link* s,b data)//进栈 { if (s == NULL) return FALSE; Node* node = (Node*)malloc(sizeof(Node)/ sizeof(char)); if (node == NULL) return FALSE; node->data = data; node->next = s->top; s->top = node; return TRUE; } int pop(Link* s,b *data)//出栈 { if (s == NULL) return FALSE; if (empty(s)) return FALSE; Node* node = s->top; *data = node->data; s->top = node->next; free(node); return TRUE; } int gettop(Link* s,b *x)//取栈头 { if (s == NULL) return FALSE; if (empty(s)) return FALSE; *x = s->top->data; return TRUE; } int destory(Link* s)//销毁栈 { if (s == NULL) return FALSE; int x; while(empty(s)!= TRUE) { pop(s,&x); } free(s); return TRUE; }