Задача такова: нужно произвести дублирование элементов, поле информации которых - чётное число , проблема заключается в том ,что в оператор if не игнорируется т.е. условие точно написано правильно , но почему-то сами манипуляции с новым элементом не работают не понимаю почему.
#include <stdio.h>
#include <locale.h>
struct TNode
{
int data;
struct TNode *next;
struct TNode *prev;
};
typedef struct TNode Node;
void CreateNode(Node** head, Node** tail, int data)
{
Node *NewNode = (Node*)malloc(sizeof(Node));
NewNode->data = data;
if ((*head) == NULL)
{
NewNode->next = NULL;
NewNode->prev = NULL;
(*tail) = NewNode;
(*head) = NewNode;
return;
}
else
{
NewNode->next = NULL;
(*tail)->next = NewNode;
NewNode->prev = (*tail);
(*tail) = NewNode;
}
}
void copy(Node** head,Node**tail)
{
Node *tmp;
tmp = (*head);
while (tmp != NULL)
{
if ((tmp->data % 2) == 0)
{
Node *P1 = (Node*)malloc(sizeof(Node));
P1->data = tmp->data;
P1->prev = tmp->prev;
tmp->prev = P1;
P1->next = tmp;
}
tmp = tmp->next;
}
}
int main()
{
setlocale(LC_ALL, "ukr");
Node *head = NULL;
Node *tail = NULL;
for (int i = 0; i < 5; i++)
{
CreateNode(&head,&tail, i + 2);
}
copy(&head, &tail);
if (head == NULL)//0 elements
{
printf("The list is empty!");
}
while (head)
{
printf("%d\n", head->data);
head = head->next;
}
getchar();
return 1;
}```