Hi everyone, just doing some practices on linked lists. So I'm trying to insert a node at the end of a linked list but I'm getting this error saying i can't access the next node using P. P is just a node pointer that i want to use to traverse though the list, please show me where I'm going wrong if you spot the mistake, thank you!
(the program compiles but crashes when i run)
Code:void InsertNewLast(dataItem value, NodeType **L) { NodeType *N, *P; N = (NodeType*)malloc(sizeof(NodeType)); N->data = value; N->next = NULL; if (*L==NULL){ // check for empy list *L = N; } else { // list is not empty P = *L; while (P){ // traverse through list till the end P = P->next; // } P->next = N; // set N to be last node } }



LinkBack URL
About LinkBacks



