0
Deleting nth value in list of nodes
Where would I go to better understand how to delete the nth cause I’m a list of nodes? Was given a 4 minute video to show how to create a list and now, “Build a linked list of 20 nodes using the addNode function you created in Problem 1. Write a function to delete the kth node of the list. k is any number between 1 and 19.” I can Chegg it, but I wanna understand this. Do the teachers get better? :,)
8 ответов
0
Just iterate through the list while counting. Stop at the nth node, take the next reference of that node and add it to the previous node.
It's like a chain of metal rings. You remove one and then connect the next one to the previous one, to reconnect the chain.
+ 1
Yah that entire program is still far beyond anything i can comprehend.
Thank you so much though, i have a better concept of this all
0
Thank you for that!
So i gave it a try and now its telling me that i gave too many iterations? Tried deleting 1-2 and same thing.
0
Mason Haines How did you iterate?
0
Heres the full code
0
Mason Haines You need to pass the first node (head) to the Delete function, not currentNode as it's implement to always point to the last element (tail).
I would also recommend that you implement it as a class.
I fixed it here if there is anything unclear.
https://code.sololearn.com/cgbXpeMj79ck/?ref=app
0
I just made a bare bones and generic implementation of LinkedList. My C++ is rusty but it should be helpful.
https://code.sololearn.com/cJR941XcGV4s/?ref=app