#include
#include
typedef int datatype;
typedef struct _node_
{
datatype data;
struct _node_ *next;
} linkstack;
linkstack *CreateEmptyStack_1()
{
linkstack *s;
s = (linkstack *)malloc(sizeof(linkstack));
s->next = NULL;
return s;
}
void CreateEmptyStack_2(linkstack **s)
{
*s = (linkstack *)malloc(sizeof(linkstack));
(*s)->next = NULL;
return;
}
int EmptyStack(linkstack *s)
{
return (NULL == s->next);
}
void ClearStack(linkstack *s)
{
linkstack *p, *q;
p = s->next;
while (p != NULL)
{
q = p;
p = p->next;
free(q);
}
s->next = NULL;
return;
}
void PushStack(linkstack *s, datatype x)
{
linkstack *p;
p = (linkstack *)malloc(sizeof(linkstack));
p->data = x;
p->next = s->next;
s->next = p;
return;
}
datatype PopStack(linkstack *s)
{
linkstack *q;
datatype x;
q = s->next;
s->next = q->next;
x = q->data;
free(q);
return x;
}
datatype GetTop(linkstack *s)
{
return s->next->data;
}
阅读(545) | 评论(0) | 转发(1) |