My issue is removing a node from the link list.
I have two structures:
typingfiff interior_inlist {int count; Four words [100]; Inner_list * next; } Inner_list; Typedef struct outer_list {four words [100]; Inner_list * Head; integer number; External * list * next; } External_list;
My problem is to remove a node from an external list link list. For example, to remove the user AAA
, the removal function should be found with the external list-> word = AAA and the node should be removed and the list should be deleted again. Must connect
. I tried code below to do this. But after finding and destroying, I am missing the list. I dont know whats wrong. Please note that there is also a linked list of the inner list in the external list.
Zero Deland (External List ** Head, Four Digits [100]) Thank you for both Nikhi Levy and Jeremy P. {Outer_list * Temp, * m; Meter = floating = * head; / * FIX # 1 * / while (temp! = NULL) {if (strcmp (temp-> word, num) == 0) {if (temp == * head) {delinner (temp-> head); / * Fix # 2 * / * Head = Temp-> Next; Free (temporary); Return; } Other {delininer (temp-> head); / * Fix # 2 * / M- & gt; Next = Temporary-> Next; Free (temporary); Return; }} And {m = temp; Temp = temp- & gt; next; }} Printf ("ELEMENT% s not found", number); } Empty Digibner (Inner_list * Head) {/ * Fix # 2 * / Initialist * Temporary; Temporary = head; While (temp! = NULL) {head = temp-> next; Free (temporary); Temporary = head; }}
Now my problem has been updated. While removing an element from the internal list, I am also trying to remove the same element from the internal list. For example: - Suppose AAA is an element of the list linked to the external list and point it with the external_list * p - this aa also can be also in an inner_list link list (in this p-> head or other internal list Maybe.) Now, the hard part again I tried to apply the same rules with the removal of external rules, but whenever I remove the main element of inner_list, it gives an error. Here's what I have tried:
zero to delodod 2 (outer list * above, internal_list ** head, four digits [100]) {inner_list * temp2, * temp, * m; External_list * p; P = Above; While (p = zero!) {M = temporarily = temp2 = p-> Head; While (temp! = NULL) {if (strcmp (temp->, num) num == 0) {if (temp == (* head)) {* head = temp- & gt; next; Free (temporary); Return; } Other {M-> Next = floating-> next; Free (temporary); Return; }} And {m = temp; Temp = temp- & gt; next; }} P = p-> next; } Printf ("element% s not found", number); }
Here I crossover when sending the node and checking all inner_list list of external_list element elements, and when the first element is removed, it crashes. Please ask for more information. I can use very dirty words. Diagnosis # 1 (Optional) - It is a good practice to start all the variables that note that
In this specific case when you handle head scanners, then you should not have any problem because M is temporarily set up, but still ..
Fix # 2 - Make sure that You want to delete the internal list completely before you release the node.
Code here (unwanted, sorry)
nozzle (external list) * head, four digits [100]) {outer_list * temporary, * m; Meter = floating = head; / * FIX # 1 * / while (temp! = NULL) {if (strcmp (temp-> word, num) == 0} {if (temp == head) {head = temp-> gt; Delinner (temp-> inner_list); / * Fix # 2 * / Free (Temporary); Return; } Other {M-> Next = floating-> next; Delinner (temp-> inner_list); / * Fix # 2 * / Free (Temporary); Return; }} And {m = temp; Temp = temp- & gt; next; }} Printf ("ELEMENT% s not found", number); } Empty Digibner (Inner_list * Head) {/ * Fix # 2 * / Initialist * Temporary; Temporary = head; While (temp! = NULL) {head = temp-> next; Free (temporary); Temporary = head; }}
Comments
Post a Comment