- Learn Data Structures and Algorithms with Golang
- Bhagvan Kommadi
- 119字
- 2021-06-24 15:37:48
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=1739025262-uuHOqvp6oXra1oUlDdp7fQB1so052ScZ-0-b257d004a23baebc1a4f65e0a77aae6e)
The next section talks about sets, which are linear data structures.