主题:[讨论]链栈的进栈和出栈怎么错了???
typedef struct linkstack
{
int data;
struct linkstack *next;
}ST;
#define LEN sizeof(ST)
#define NULL 0
#include <stdio.h>
#include <malloc.h>
void main()
{
int num[5],i;
ST *top, *push(ST *top,int x);
int pop(ST *top);
top=(ST *)malloc(LEN);
top=NULL;
for(i=0;i<5;i++)
{
printf("Please input the %d number:",i+1);
scanf("%d",&num[i]);
}
printf("The push numbers:\n");
for(i=0;i<5;i++)
printf("%d\t",num[i]);
for(i=0;i<5;i++)
top=push(top,num[i]);
for(i=0;i<5;i++)
printf("%d",pop(top));
}
ST *push(ST *top,int x)
{
ST *p;
p=(ST *)malloc(LEN);
p->data=x;
p->next=top;
top=p;
return top;
}
int pop(ST *top)
{
ST *p;
int num;
p=top;
num=top->data;
top=top->next;
free(p);
return num;
}
{
int data;
struct linkstack *next;
}ST;
#define LEN sizeof(ST)
#define NULL 0
#include <stdio.h>
#include <malloc.h>
void main()
{
int num[5],i;
ST *top, *push(ST *top,int x);
int pop(ST *top);
top=(ST *)malloc(LEN);
top=NULL;
for(i=0;i<5;i++)
{
printf("Please input the %d number:",i+1);
scanf("%d",&num[i]);
}
printf("The push numbers:\n");
for(i=0;i<5;i++)
printf("%d\t",num[i]);
for(i=0;i<5;i++)
top=push(top,num[i]);
for(i=0;i<5;i++)
printf("%d",pop(top));
}
ST *push(ST *top,int x)
{
ST *p;
p=(ST *)malloc(LEN);
p->data=x;
p->next=top;
top=p;
return top;
}
int pop(ST *top)
{
ST *p;
int num;
p=top;
num=top->data;
top=top->next;
free(p);
return num;
}