在“打印”期间,链表的元素。 “(code1)”正在打印所有元素,而“(code2)”是否正在打印元素接受“ FIRST”元素?

时间:2019-10-12 06:08:03

标签: c data-structures linked-list

使用的语言-C语言
编译器-GCC
问题-在“打印”链接列表的元素期间。 “(code1)”打印所有元素,而“(code2)”打印元素接受“ FIRST”元素,为什么?

工作代码1:---

`void print()
 {
struct node *temp = head;
printf("List is :");
while(temp!=NULL)   **PRINTING FIRST ELEMENT**
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}`

非工作代码2:---

void print()
{
struct node *temp = head;
printf("List is :");
while(temp->next!=NULL)   **NOT PRINTING FIRST ELEMENT**   
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}

0 个答案:

没有答案