
上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:

Let's take a look at doubly linked list in the next section.