March 2019
Intermediate to advanced
336 pages
9h 9m
English
The AddToHead method adds the node to the start of the linked list. The AddToHead method of the LinkedList class has a parameter integer property. The property is used to initialize the node. A new node is instantiated and its property is set to the property parameter that's passed. The nextNode points to the current headNode of linkedList, and headNode is set to the pointer of the new node that's created, as shown in the following code:
//AddToHead method of LinkedList classfunc (linkedList *LinkedList) AddToHead(property int) { var node = Node{} node.property = property if node.nextNode != nil { node.nextNode = linkedList.headNode } linkedList.headNode = &node}
When the node with the 1 property is added to the head, ...
Read now
Unlock full access