Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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ā]
1 Resposta
0
thank you, cleared my confusion!