Solution Review: Construct a Double-Linked List
This lesson discusses the solution to the challenge given in the previous lesson.
package mainimport ("container/list""fmt")func insertListElements(n int)(*list.List){ // add elements in list from 1 to nlst := list.New()for i:=1;i<=n;i++{lst.PushBack(i) // insertion here}return lst}func main() {n := 5 // total number of elements to be insertedmyList := insertListElements(n) // function callfor e := myList.Front(); e != nil; e = e.Next() {fmt.Println(e.Value) // printing values of list}}
Get hands-on with 1400+ tech skills courses.