Learn Data Structures and Algorithms with Golang
上QQ阅读APP看书,第一时间看更新

The main method

In the following code snippet, the main method calls the NodeBetweenValues property with firstProperty and secondProperty. The node property between values 1 and 5 is printed:

// main method
func main() {
var linkedList LinkedList
linkedList = LinkedList{}
linkedList.AddToHead(1)
linkedList.AddToHead(3) linkedList.AddToEnd(5)
linkedList.AddAfter(1,7)
fmt.Println(linkedList.headNode.property)
var node *Node
node = linkedList.NodeBetweenValues(1,5)
fmt.Println(node.property)
}

The main method creates a linked list. The nodes are added to the head and end. The node between values 1 and 5 is searched and its property is printed.

Run the following command to execute the doubly_linked_list.go file:

go run doubly_linked_list.go

After executing the preceding command, we get the following output:

The next section talks about sets, which are linear data structures.