Dzień Dobry,
Nie wiem czemu, gdy gdy dodaję element do listy, to wskaźnik po wyjściu z funkcji addToEnd zostaje nie zmieniony.
#include <stdio.h>
#include <stdlib.h>
typedef struct Node Node;
struct Node
{
int wartosc;
Node *next;
Node *prev;
};
void addToEnd(Node *head, Node *tail, const int *liczba)
{
Node *tmp = (Node*) malloc(sizeof(Node));
tmp->wartosc = *liczba;
tmp->next = NULL;
tmp->prev = NULL;
if(head == NULL)
{
printf("baba \n");
printf("head = %d", head);
head = tmp;
printf("head = %d\n", head);
tail = tmp;
head->next = tail;
tail->prev = head;
}
else
{
printf("jaga \n");
tmp->prev = tail;
tail->next = tmp;
}
}
int main()
{
Node *head = NULL;
Node *tail = NULL;
int t = 4;
int wartosc;
while (t--)
{
scanf("%d", &wartosc);
addToEnd(head, tail, &wartosc);
}
printf(" head = %d\n", head->wartosc);
printf(" tail = %d\n", tail->wartosc);
return 0;
}