C doubly linked circular list insert -
doesn't insert , doesn't keep adresses of next , prev node: i'm trying read input file; can read data corectly , based on every line, creates aeronava object. seems insert doesn't work.any suggestions?
void insertfav_av(favnode*list, aeronava *av){ favnode* nn = (favnode*)malloc(sizeof(favnode)); //first = list; nn->infoutil = (aeronava*)malloc(sizeof(aeronava)); nn->infoutil->idaeronava = (char*)malloc(strlen(av->idaeronava) + 1); //strcpy(nn->infoutil->idaeronava, av->idaeronava); nn->infoutil = av; if (first == null){ nn->prev = nn->next = nn; first = nn; } else{ list = first; while (list->next != first){ list = list->next; } nn->prev = list; list->next = nn; nn->next = first; } } struct aeronava{ char* idaeronava; tipa tipaero; short int nrlocuri; double greutatemaxima; }; struct favnode{ favnode*next; favnode*prev; aeronava* infoutil; };
nn->prev = list; // 1 list->next = nn; // 2 nn->next = first; // 3
lines 1 , 2 link nn
list
in both directions, line 3 links nn
first
in 1 direction only. lack opposite link update here:
first->prev = nn;
Comments
Post a Comment