AddAtEnd adds a new snode with given value at the end of the list.
(val T)
| 30 | |
| 31 | // AddAtEnd adds a new snode with given value at the end of the list. |
| 32 | func (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. |