为何在链栈里面传入指针到子函数里面却无法传出到主函数中啊,没理由啊,求解!!!
源程序:#include<stdio.h>
#include<stdlib.h>
typedef struct snode
{
int data;
struct snode *next;
}stacknode;
int x;
void push_seqstack(int x,stacknode *top)/*入栈*/
{
stacknode *p;
p=(stacknode *)malloc(sizeof(stacknode));
p->data=x;
p->next=top;
top=p;
}
stacknode *pop_seqstack(stacknode *top) /*出栈*/
{
stacknode *p;
if(top->next==NULL)
{
printf("栈空\n");
return NULL;
}
else
{
p=top;
top=top->next;
x=p->data;
free(p);
return top;
}
}
void *init(stacknode *s)
{
s=(stacknode*)malloc(sizeof(stacknode));
s->next=NULL;
return s;
}
void main()
{
int i,n,y;
stacknode *top;
stacknode *s;
init(s);
top=s;
printf("输入栈个数:");
scanf("%d",&n);
printf("输入栈:\n");
for(i=0;i<n;i++)
{
scanf("%d",&y);
push_seqstack(y,top);
}
printf("出栈:\n");
for(i=0;i<n;i++)
{
top=pop_seqstack(top);
printf("%d ",x);
}
printf("\n");
}
如题,感谢各位高手的解答,小弟疑惑啊!