MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / AddAtEnd

Method AddAtEnd

structure/linkedlist/singlylinkedlist.go:32–46  ·  view source on GitHub ↗

AddAtEnd adds a new snode with given value at the end of the list.

(val T)

Source from the content-addressed store, hash-verified

30
31// AddAtEnd adds a new snode with given value at the end of the list.
32func (ll *Singly[T]) AddAtEnd(val T) {
33 n := NewNode(val)
34
35 if ll.Head == nil {
36 ll.Head = n
37 ll.length++
38 return
39 }
40
41 cur := ll.Head
42 for ; cur.Next != nil; cur = cur.Next {
43 }
44 cur.Next = n
45 ll.length++
46}
47
48// DelAtBeg deletes the snode at the head(beginning) of the list
49// and returns its value. Returns false if the list is empty.

Callers

nothing calls this directly

Calls 1

NewNodeFunction · 0.70

Tested by

no test coverage detected