程序运行不了,

chenjia1220 2006-09-22 02:46:46
这是个栈的程序:
#include <stdio.h>
#include <malloc.h>
struct list{
int data;
struct list *next;
};
struct stract{
struct list *top;
struct list *bot;
};
int data;
sturct stract stack;
void inits(struct stract s){
struct list *b;
b=(struct list *)malloc(sizeof(struct list));
b->next=null;
s.top=b;
s.bot=b;
}
void push(struct stract s,int a){
struct list *b;
b=(struct list *)malloc(sizeof(struct list));
b->next=s.top;
s.top=b;
b->data=a;
}
void pop(struct stract s,int a){
struct list *b;
b=s.top;
s.top=s.top->next;
a=b->data;
}
int gettop(struct stract s){
return s.top->data;
}
main(){

inits(stack);
push(stack,1);
println("%d",gettop(stack));
}
...全文
101 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangyangman 2006-09-22
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <malloc.h>
struct list{
int data;
struct list *next;
};
struct stract{
struct list *top;
struct list *bot;
};
int data;
struct stract stack;
void inits(struct stract *s){
struct list *b;
b=(struct list *)malloc(sizeof(struct list));
b->next=NULL;
s->top=b;
s->bot=b;
}
void push(struct stract *s,int a){
struct list *b;
b=(struct list *)malloc(sizeof(struct list));
b->next=s->top;
s->top=b;
b->data=a;
}
int gettop(struct stract s){
return s.top->data;
}
main(){

inits(&stack);
push(&stack,1);
printf("%d",gettop(stack));
}
函数改好了,LZ再自己改改POP函数吧

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧