Package Mainimport "FMT"//define nodes type node struct {Data intnext *node}/** return first node * H header node */func getfirst (H *node) *node {if H . Next = nil {return Nil}return h.next}/** returns the last node * H header node */func getlast (H *node) *node {if H.next = nil {return Nil}i: = Hfor I.next! = Nil {i = i.nextif I.next = nil {return I}}return nil}//take length func getlength (h *node) int {var I int = 0n: = Hfor N.next! = Nil {i++n = N.next}return i}//Insert a node//h: Head node//d: node to be inserted//p: position to insert func insert (H, D *node, p int) bool {if H.N Ext = = Nil {H.next = Dreturn true}i: = 0n: = hfor N.next! = Nil {i++if i = = p {if N.next.next = nil {n.next = Dreturn tru e} else {d.next = N.nextn.next = D.nextreturn True}}n = n.nextif N.next = nil {n.next = Dreturn True}}return false}//take out the specified Node func getloc (H *node, p int) *node {if p < 0 | | p > GetLength (h) {return nil}var i int = 0n: = hfor N.next! = Nil { I++n = n.nextif i = = p {return N}}return Nil}func main () {var h nodeli: = []int{2, 4, 3}for _, L: = range Li {var d noded. Data = Linsert (&h,&d, L)}var i nodels: = []int{5, 6, 4}for _, S: = range ls {var dd nodedd.data = Sinsert (&i, &DD, s)}sum: = 0su m = Getloc (&h, 3). data*100 + Getloc (&h, 2). Data*10 + getloc (&h, 1). Data + Getloc (&i, 3). data*100 + Getloc (&i, 2). Data*10 + getloc (&i, 1). Datafmt.println (SUM)}
Go language link list exercises