March 2019
Intermediate to advanced
336 pages
9h 9m
English
The AddToEnd method adds the node at the end of the list. In the following code, the current lastNode is found and its nextNode property is set as the added node:
//AddToEnd method adds the node with property to the endfunc (linkedList *LinkedList) AddToEnd(property int) { var node = &Node{} node.property = property node.nextNode = nil var lastNode *Node lastNode = linkedList.LastNode() if lastNode != nil { lastNode.nextNode = node }}
In the following screenshot, the AddToEnd method is invoked when the node with a property value of 5 is added to the end. Adding the property through this method creates a node with a value of 5. The last node of the list has a property value of 5. The nextNode property of lastNode is nil ...
Read now
Unlock full access