首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C数据结构。新手。

2012-10-11 
C数据结构。新手求救。急急急。int main(){linkstacknode nlinkstack tint i0int mstackelementtype ys

C数据结构。新手求救。急急急。
int main()
{
 linkstacknode n;
 linkstack t;
 int i=0;
 int m;
 stackelementtype ys;
 in(&n);
  printf("请输入链栈的元素个数:");
 scanf("%d ",i);
 printf("请输入链栈的元素:");
 for(int k=1;k<=i;k++)
 {
  scanf("%d ",&m);  
 push(t,&n,m);
 }
 printf("现在弹出首元素……");
 pop( t,&ys);
 return 0;
}这是主函数;

int push(linkstack top,linkstacknode *temp,stackelementtype x)
{
temp->data=x;
temp->next=top->next;
top->next=temp;
return (TRUE);
}这是问题所在的函数。

运行之后提示push(t,&n,m);在主函数中 local variable 't' used without having been initialized
这是怎么回事??应该怎么做呢?


[解决办法]
linkstack t;定义之后没有初始化就直接调用push和pop等函数了,参考标准的栈的写法,例如:
linkstack* t = ls_create();
ls_push(t, n);
n = ls_pop(t);
ls_destory(t);
一般函数需要传linkstack指针进去,类似int push(linkstack* this, int n)这样的接口。

热点排行