Answered step by step
Verified Expert Solution
Question
1 Approved Answer
hI GUYS c++ trying to delete nodes with the given value. i write this code and compile perfectly, however, i do get a seg fault
hI GUYS
c++
trying to delete nodes with the given value. i write this code and compile perfectly, however, i do get a seg fault somehow. I couldnt think of any bugs in this code. Plese take a look and tell me whats wrong
btw lets say linkedlist is 3-3-2-3-null after i input the list and 3, the list should be 2-null;
void deleteNode Iteratively (LinkedListList, int value){ Node next: Node *p List->head; Node prev = NULL; while (List->head->data value) p = List->head->next ; delete List->head List->head = p; //if the head node has the same value, delete them and set a new head assert (List->head !=NULL) ; while (p.= NULL){ // start iterate if (p->data value) next = p->next ; delete p: p = next; if (p NULL) List->ta!! //reset tall = prev; else prev = p; // point to the previous node, incase of deleting the tail p->nextStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started