level 1
狂一户
楼主
#include <iostream>
using namespace std;
typedef char ElemType;
typedef struct linknode
{
ElemType data; //数据域
struct linknode *next; //指针域
} LiStack; //链栈类型定义
void InitStack(LiStack *&s) //初始化链栈s;
{
s=(LiStack *)malloc(sizeof(LiStack));
s->next=NULL;
}
void ClearStack(LiStack *&s) //释放栈
{
LiStack *p=s->next;
while (p!=NULL)
{
free(s);
s=p;
p=p->next;
}
free(s); //s指向尾结点,释放其空间
}
int StackLength(LiStack *s) //判断长度
{
int i=0;
LiStack *p;
p=s->next;
while (p!=NULL)
{
i++;
p=p->next;
}
return(i);
}
int StackEmpty(LiStack *s) //判断是否为空
{
return(s->next==NULL);
}
void Push(LiStack *&s,ElemType e) //进栈
{
LiStack *p;
p=(LiStack *)malloc(sizeof(LiStack));
p->data=e;
p->next=s->next; //插入*p结点作为第一个数据结点
s->next=p;
}
int Pop(LiStack *&s,ElemType &e) //出栈
{
LiStack *p;
if (s->next==NULL) //栈空的情况
return 0;
p=s->next; //p指向第一个数据结点
e=p->data;
s->next=p->next;
free(p);
return 1;
}
int GetTop(LiStack *s,ElemType &e) //读取栈顶元素
{
if (s->next==NULL) //栈空的情况
2010年11月02日 09点11分
1
using namespace std;
typedef char ElemType;
typedef struct linknode
{
ElemType data; //数据域
struct linknode *next; //指针域
} LiStack; //链栈类型定义
void InitStack(LiStack *&s) //初始化链栈s;
{
s=(LiStack *)malloc(sizeof(LiStack));
s->next=NULL;
}
void ClearStack(LiStack *&s) //释放栈
{
LiStack *p=s->next;
while (p!=NULL)
{
free(s);
s=p;
p=p->next;
}
free(s); //s指向尾结点,释放其空间
}
int StackLength(LiStack *s) //判断长度
{
int i=0;
LiStack *p;
p=s->next;
while (p!=NULL)
{
i++;
p=p->next;
}
return(i);
}
int StackEmpty(LiStack *s) //判断是否为空
{
return(s->next==NULL);
}
void Push(LiStack *&s,ElemType e) //进栈
{
LiStack *p;
p=(LiStack *)malloc(sizeof(LiStack));
p->data=e;
p->next=s->next; //插入*p结点作为第一个数据结点
s->next=p;
}
int Pop(LiStack *&s,ElemType &e) //出栈
{
LiStack *p;
if (s->next==NULL) //栈空的情况
return 0;
p=s->next; //p指向第一个数据结点
e=p->data;
s->next=p->next;
free(p);
return 1;
}
int GetTop(LiStack *s,ElemType &e) //读取栈顶元素
{
if (s->next==NULL) //栈空的情况