0

Deleting nodes from linked list errors (C)

https://code.sololearn.com/cpCzmBkmemux/#c I'm working on nodes and i have this problem in the two functions detonanodo and detonavalore: the first one deletes the node at a certain position and the second deletes a node with a specified value, they both work but not if the node is in first or last position.

22nd Jun 2020, 8:48 AM
Guido Parlatore
Guido Parlatore - avatar
6 Respuestas
+ 2
This situation seems like someone has missed the correct handling of NULL. You need to be very careful about how you handle NULL value and the functions detonanodo you might want to change the operator at line 76. Adding head and tail handlers to the code is a good idea. Handle the first and last position separate form the rest of the list within the function.
22nd Jun 2020, 9:16 AM
Anubhav Mattoo
Anubhav Mattoo - avatar
+ 2
Guido Parlatore No, you can add the cases for handling them within the current functions by using if or switch, whichever you prefer.
22nd Jun 2020, 9:53 AM
Anubhav Mattoo
Anubhav Mattoo - avatar
+ 2
https://code.sololearn.com/ct280pBU9UQB/?ref=app Here, I have reworked the detonanodo function including the head and tail case(just a small if). Compare the codes to check for changes.
22nd Jun 2020, 10:52 AM
Anubhav Mattoo
Anubhav Mattoo - avatar
0
So should i create two new functions just for those two cases?
22nd Jun 2020, 9:33 AM
Guido Parlatore
Guido Parlatore - avatar
0
I tried to but it doesnt work, can you tell me how could i do it?
22nd Jun 2020, 9:55 AM
Guido Parlatore
Guido Parlatore - avatar
0
Now the function works for the last node but it still gives problem with the head
22nd Jun 2020, 12:45 PM
Guido Parlatore
Guido Parlatore - avatar