![Learn Data Structures and Algorithms with Golang](https://wfqqreader-1252317822.image.myqcloud.com/cover/744/36698744/b_36698744.jpg)
上QQ阅读APP看书,第一时间看更新
The main method
The main method adds the nodes with integer properties of 1, 3, and 5, as shown in the following code. A node with an integer property of 7 is added after the node with an integer property of 1. The IterateList method is invoked on the linkedList instance, as follows:
// main method
func main() {
var linkedList LinkedList
linkedList = LinkedList{}
linkedList.AddToHead(1)
linkedList.AddToHead(3)
linkedList.AddToEnd(5)
linkedList.AddAfter(1,7)
linkedList.IterateList()
}
The main method adds 1 and 3 to the head of the linked list. 5 is added to the end. 7 is added after 1. The linked list will be 3, 1, 7, and 5.
Run the following commands to execute the linked_list.go file:
go run linked_list.go
After executing the preceding command, we get the following output:
![](https://epubservercos.yuewen.com/AA6936/19470380301498306/epubprivate/OEBPS/Images/81213159-77ca-4f5d-bcda-3822916087df.png?sign=1738932431-WisJTk7nYlwxicIfpXTsERw99m5yjlHs-0-fb9d2ef4d9ca850d67157f2709656bd1)
Let's take a look at doubly linked list in the next section.