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

Method AddAtBeg

structure/linkedlist/singlylinkedlist.go:24–29  ·  view source on GitHub ↗

AddAtBeg adds a new snode with given value at the beginning of the list.

(val T)

Source from the content-addressed store, hash-verified

22
23// AddAtBeg adds a new snode with given value at the beginning of the list.
24func (ll *Singly[T]) AddAtBeg(val T) {
25 n := NewNode(val)
26 n.Next = ll.Head
27 ll.Head = n
28 ll.length++
29}
30
31// AddAtEnd adds a new snode with given value at the end of the list.
32func (ll *Singly[T]) AddAtEnd(val T) {

Callers

nothing calls this directly

Calls 1

NewNodeFunction · 0.70

Tested by

no test coverage detected