#include "iostream.h"
//这里要加上我们默认的常量头文件
typedef int SElemType;
typedef struct LNode
{
SElemType data;
struct LNode *next;
}LNode,*LinkStack;
Status InitStack(LinkStack &S)
{
S=new LNode;
S->next=NULL;
return OK;
}
int StackLength(LinkStack S)
{
LinkStack p;
p=new LNode;
int i=0;
p=S->next;
while(p)
{
i++;
p=p->next;
}
return i;
}
Status Pop(LinkStack &s,SElemType &e)
{
if(s->next!=NULL)
{
e=s->next->data;
s->next=s->next->next;
return OK;
}
else return ERROR;
}
Status ClearStack(LinkStack &S)
{
LinkStack p;
p=new LNode;
while(S->next)
{
p=S->next;
S->next=S->next->next;
delete p;
}
return OK;
}
Status GetTop(LinkStack &S,SElemType &e)
{
LinkStack p=new LNode;
p=S->next;
e=p->data;
return OK;
}
Status Push(LinkStack &S,SElemType e)
{
LinkStack p;
p=new LNode;
p->data=e;
p->next=S->next;
S->next=p;
return OK;
}
Status DestroyStack(LinkStack &S)
{
LinkStack q;
while(S)
{
q=S->next;
delete S;
S=q;
}
return OK;
}
Status StackEmpty(LinkStack &S)
{
LinkStack p=S;
if(p->next)
return FALSE;
else return TRUE;
}
posted on 2007-06-06 23:34
星梦情缘 阅读(1532)
评论(0) 编辑 收藏 引用 所属分类:
活动程序