The NodeBetweenValues method

The NodeBetweenValues method of the LinkedList class returns the node that has a property lying between the firstProperty and secondProperty values. The method traverses the list to find out whether the firstProperty and secondProperty integer properties match on consecutive nodes, as follows:

//NodeBetweenValues method of LinkedList
func (linkedList *LinkedList) NodeBetweenValues(firstProperty int,secondProperty int) *Node{
var node *Node
var nodeWith *Node
for node = linkedList.headNode; node != nil; node = node.nextNode {
if node.previousNode != nil && node.nextNode != nil {
if node.previousNode.property == firstProperty && node.nextNode.property ==
secondProperty{
nodeWith = node
break;
}
}
}
return nodeWith
}

The example output after the node between the values method was invoked with 1 and 5 is shown in the following screenshot. The nextNode of the lastNode is set to the node with a value of 5. The node with a property value of 7 is between the nodes with property values of 1 and 5:

Let's take a look at the AddToHead method in the next section.