#include<stdio.h>
#include<stdlib.h>
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}linkstack;
linkstack *top;
void initiate(linkstack *top)//链栈的初始化
{
top=NULL;
return ;
}
linkstack * pushls(linkstack *top,datatype x)//链栈的入栈
{
linkstack *q;
q=(linkstack *)malloc(sizeof(linkstack));
q->data=x;
q->next=top;
top=q;
return top;
}
linkstack * popls(linkstack *top,datatype *x)//链栈的出栈
{
linkstack *e;
if(top==NULL)
{printf("空栈");return NULL;}
else
{
*x=top->data;
e=top;
top=top->next;
free(e);
return top;
}
}
int main()
{
int i=0,j=0,a[6];
initiate(top);
// printf("%s",top);
for(;i<=5;i++)
top=pushls(top,i);
for(;j<=5;j++)
top=popls(top,&a[j]);
while(j--)
{printf("%d",a[j]);}
return 0;
}
#include<stdlib.h>
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}linkstack;
linkstack *top;
void initiate(linkstack *top)//链栈的初始化
{
top=NULL;
return ;
}
linkstack * pushls(linkstack *top,datatype x)//链栈的入栈
{
linkstack *q;
q=(linkstack *)malloc(sizeof(linkstack));
q->data=x;
q->next=top;
top=q;
return top;
}
linkstack * popls(linkstack *top,datatype *x)//链栈的出栈
{
linkstack *e;
if(top==NULL)
{printf("空栈");return NULL;}
else
{
*x=top->data;
e=top;
top=top->next;
free(e);
return top;
}
}
int main()
{
int i=0,j=0,a[6];
initiate(top);
// printf("%s",top);
for(;i<=5;i++)
top=pushls(top,i);
for(;j<=5;j++)
top=popls(top,&a[j]);
while(j--)
{printf("%d",a[j]);}
return 0;
}