Modifying a linkedlist | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Resposta
0
thank you, cleared my confusion!
30th Sep 2019, 3:21 PM
Jamie Charles