Hey guys. So i have a program that uses linked lists, and it can insert, delete, and print the list. My insertion works just fine, but there seems to be an error with the deletion. XD
If I dont use free(), the program works well.Code:void deleteNode(link *head, int input) { link p; link curr; link dealloc; int match=0; p=*head; while(p!=NULL) { if(p->x==input) match++; p=p->next; } if(match>=1) { if((*head)->x == input) { dealloc=*head; *head=(*head)->next; free(dealloc); } else { p=*head; curr = p->next; link temp; while(curr!=NULL && curr->x!=input) { p = p->next; curr = p->next; } p->next=curr->next; free(curr); } printList(head); } else { printf("NUMBER NOT FOUND!"); printList(head); } } }
When I try to use free(), a window appears and says something about a debug error. Can you figure out what's wrong? How do I fix this? Thank you![]()



3Likes
LinkBack URL
About LinkBacks




