![Learn Data Structures and Algorithms with Golang](https://wfqqreader-1252317822.image.myqcloud.com/cover/744/36698744/b_36698744.jpg)
上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:
![](https://epubservercos.yuewen.com/AA6936/19470380301498306/epubprivate/OEBPS/Images/617c65dd-924b-4aa7-b9d1-9d51d4688881.png?sign=1739594327-WEUqeuQvv5WIzk3wvslz0XMIlwfYc6cD-0-3d58606e1a09c6f1686b4d8b6ade5552)
The next section talks about sets, which are linear data structures.