This is another golang tutorial that help to understand data structure.We will create simple Doubly Linked list example using golang.
We will create struct that have value,prev pointer and next node pointer.Creating following method help to create and traverse Linked list.
insertNode()
: This method will use insert node into list.Display()
: Traverse and display Linked List data into console in sequential.DisplayReverse()
: Traverse and display Linked List data in reverse order.
Doubly Linked List Implementation in Golang
Creating a file main.go
file add below steps code into this file.
Step 1: We will create package and import packages.
package main import ( "fmt" "math/rand" )
Step 2: Now create struct for list and list node.
type Node struct { num int prev *Node next *Node } type List struct { tail *Node start *Node }
Step 3: We will create main()
and supportive function.
func main() { items := &List{} size := 10 //rand_number := make([]int, size, size) for i := 0; iAs per above code, Created insertNode,DisplayReverse and Display method for create list,traverse reverse list and display linked list data.
The post How To Implement Doubly Linked List Using Golang appeared first on Rest Api Example.