【发布时间】:2014-11-12 20:40:24
【问题描述】:
我正在尝试实现一些队列操作,但即使在推送所有元素之后,前面似乎仍然是 NULL。在主函数中,我只是读取一些元素并将它们推入队列。我的代码:
typedef struct nod
{
int info;
struct nod *link;
}tnod;
tnod *front=NULL,*rear=NULL;
void push(tnod *front,int item)
{
tnod *tmp;
tmp=malloc(sizeof(tnod));
if(tmp==NULL)
{
printf("Memorie indisponibila\n");
return;
}
tmp->info = item;
tmp->link=NULL;
if(front==NULL) /*daca stiva e goala*/
{front=tmp; printf("%d",front->info);}
else
rear->link = tmp;
rear=tmp;
}
提前致谢。
【问题讨论】: