Modifying a linkedlist | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Modifying a linkedlist

I have to make my own implementation of a linkedlist. I know for methods like add, delete, etc, I can do this: create a new node and set it to head: Node temp = head Say head has these attached to it: [“a”] - [“b”] - [“c”] Then would temp look like this?: [“a”] - [“b”] - [“c”] I know that to add an node to the end, I can loop through the linkedlist until null: Node newNode = newNode(data) while (temp.next != null) { temp = temp.next; } temp.next = newNode But wouldn’t the linkedlist look like this because I’m setting a new next each time?: [“c”] - [“e”] This has made me confused. I assume I need to modify the original linked list and get: [“a”] - [“b”] - [“c”] - [“e”]

30th Sep 2019, 2:19 PM
Jamie Charles
1 Answer
0
thank you, cleared my confusion!
30th Sep 2019, 3:21 PM
Jamie Charles