typedef int ElemType;
typedef int Status;
#include<stdio.h>
#define true 1
#define false 0
typedef struct Snode
{
ElemType data;
struct Snode *next;
}Snode,*pstack;
typedef struct {
pstack top;
}linkstack;
Status Initstack(linkstack &S)
{
S.top=NULL;
return true;
}
Status Gettop(linkstack S,ElemType &e)
{
if(S.top==NULL)
{
return false;}
Snode *p=S.top;
e=p->data;
return true;
}
Status Destroystack(linkstack &S)
{
Snode *p=S.top;
p->next=NULL;
free(p);
return true;
}
Status Clearstack(linkstack &S)
{
Snode *p=S.top;
p->next=NULL;
return true;
}
Status stackempty(linkstack S)
{
if(S.top==NULL)
{
return true;
}
else
return false;
}
Status stacklength(linkstack S)
{
int j=0;
Snode *p=S.top;
while(p->next!=NULL)
{
j++;
p=p->next;
}
return j;
}
Status push(linkstack &S,ElemType e)
{
Snode *q=(pstack)malloc(sizeof(Snode));
if(!q)
{
return false;
}
q->data=e;
q->next=S.top;
S.top=q;
return true;
}
Status pop(linkstack &S,ElemType &e)
{
Snode *p=S.top;
if(S.top==NULL)
{
return false;
}
e=p->data;
S.top=p->next;
free(p);
return true;
}
Status stacktraverse(linkstack S)
{
Snode *p=S.top;
while(p!=NULL)
{
printf("%d",p->data);
p=p->next;
}
return true;
}
#include<stdio.h>
#include<stdlib.h>
#include<linkstack1.h>
int main()
{
linkstack s;
Initstack(s);
push(s,1);
push(s,2);
push(s,3);
push(s,4);
push(s,5);
int n;
pop(s,n);
stacktraverse(s);
system("pause");
}