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â]
1 RĂ©ponse
0
thank you, cleared my confusion!