gpt4 book ai didi

C中的循环链表

转载 作者:太空宇宙 更新时间:2023-11-04 06:36:28 24 4
gpt4 key购买 nike

<分区>

我正在尝试遍历 C 中的循环单链接列表,但它显示了除最后一个元素之外的所有元素。错误在哪里?显示功能的其他部分的条件可能会发生变化?但是条件应该是什么?链接列表的显示和创建功能是:

struct node
{

int data;
struct node *next;
}*last;

void create(int num)
{

struct node *t,*q;
t=(struct node*)malloc(sizeof(struct node));
t->data=num;
//list is empty
if(last==NULL){
last=t;
t->next=last;
}
else
{
t->next=last->next;
last->next=t;
last=t;
}
return;
}

void display()
{

struct node *q;
q=(struct node*)malloc(sizeof(struct node));
if(last==NULL){
printf("no items in the list");
return;

}
else{
q=last->next;
while(q!=last){
printf("%d\n",q->data);
q=q->next;
}
}
//return;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com