| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 563 人关注过本帖
标题:各位大哥,帮我看看我的数据结构错在哪里!!!谢谢了
只看楼主 加入收藏
xiaochong4
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-12-3
收藏
 问题点数:0 回复次数:1 
各位大哥,帮我看看我的数据结构错在哪里!!!谢谢了
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct zhai)
struct zhai
{int data;
struct zhai *next;
};
struct zhai *create(void)
{struct zhai *top;
top=NULL;
return(top);
}
;
int pushzhai(struct zhai *top,int x)
{struct zhai *p;
p=(struct zhai *)malloc(LEN);
if(!p)
{printf("error\n");
return(0);
}
p->data=x;
p->next=top-next;
top->next=p;
return(1);
};
int getzhai(struct zhai *top)
{return(top->data);
};
void main()
{
struct zhai *top;
top=create();
pushzhai(top,1);
pushzhai(top,2);
int i;
i=getzhai(top);
printf("%d",i);
}
为何并不输出2,而输出0并提示错误!!望大侠们指教
搜索更多相关主题的帖子: 数据结构 zhai struct top int 
2005-12-03 15:48
trroy0525
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-12-1
收藏
得分:0 
你的进栈操作有问题把
好象应该是这样的
p->data=x;
p->next=top;
top=p;
2005-12-03 17:31
快速回复:各位大哥,帮我看看我的数据结构错在哪里!!!谢谢了
数据加载中...
 
   



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

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