初学栈 遇到问题了 谁能帮下我么
#include <stdio.h>#include <stdlib.h>
struct st
{
int a;
struct st * pNext;
};
struct zh
{
struct st * pTop;
struct st * pBottom;
};
struct zh * create(); //创建栈
void push(struct zh *,int); //压栈
void show(struct zh *); //遍历
int main()
{
int num_z;
struct zh * pZh;
printf("请输入栈数量:");
scanf("%d",&num_z);
pZh=create(); //这里的pZh还有地址
push(pZh,num_z); //传入的pZh就是别的地址了
show(pZh);
}
struct zh * create()
{
struct st * pHead;
struct zh * Zh;
pHead=(struct st *)malloc(sizeof(struct st ));
pHead->pNext =NULL;
Zh->pBottom =pHead;
Zh->pTop =pHead;
return Zh ;
}
void push(struct zh * pZh,int a) //地址不是原来的 所以也输出不了
{
int b;
struct st * pAdd;
for(b=1;b<=a;b++)
{
pAdd =(struct st *)malloc(sizeof(struct st));
printf("请输入第%d个栈的值:",b);
scanf("%d",&pAdd->a );
pAdd->pNext =pZh->pTop ;
pZh->pTop =pAdd;
}
printf("压栈完毕");
return;
}
void show(struct zh * pZh)
{
while(pZh->pTop !=NULL )
{
printf("%d ",pZh->pTop ->a );
pZh->pTop =pZh->pTop ->pNext ;
}
printf("\n输出完毕");
return;
}
也许要有别的问题但我没有发现 希望能够得到解答 谢谢。