| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 494 人关注过本帖
标题:初学栈 遇到问题了 谁能帮下我么
取消只看楼主 加入收藏
kd83kdi93
Rank: 2
等 级:论坛游民
帖 子:65
专家分:52
注 册:2011-9-18
结帖率:70%
收藏
已结贴  问题点数:5 回复次数:0 
初学栈 遇到问题了 谁能帮下我么
#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;
}

 也许要有别的问题但我没有发现   希望能够得到解答  谢谢。
搜索更多相关主题的帖子: include create 
2011-10-31 21:36
快速回复:初学栈 遇到问题了 谁能帮下我么
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021612 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved