#include <stdio.h>
#include <conio.h>
struct node
{
int data;
struct node* next;
};
int main()
{
struct node* head = NULL;
struct node* second = NULL;
struct node* third = NULL;
head = (struct node*)malloc(sizeof(struct node));
second = (struct node*)malloc(sizeof(struct node));
third = (struct node*)malloc(sizeof(struct node));
head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;
struct node* new1;
struct node* temp1;
temp1 = head;
while(temp1->next != NULL)
{
temp1 = temp1->next;
}
new1 = (struct node*)malloc(sizeof(struct node));
temp1->next = new1;
new1->data = 5;
new1->next = NULL;
while(temp1 != NULL)
{
printf("%d ",temp1->data);
temp1 = temp1->next;
}
return 0;
}
Это программа для вставки узла в конец связанного списка. Ожидаемый результат = 1 2 3 5, 5 - значение нового узла здесь. Но текущий вывод = 3 5. Я не знаю, где я ошибаюсь. Любой ответ будет оценен.Вставка узла в конец связанного списка