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

Method Push

structure/stack/stacklinkedlist.go:25–33  ·  view source on GitHub ↗

push add value to last index

(n any)

Source from the content-addressed store, hash-verified

23
24// push add value to last index
25func (ll *Stack) Push(n any) {
26 newStack := &Node{} // new node
27
28 newStack.Val = n
29 newStack.Next = ll.top
30
31 ll.top = newStack
32 ll.length++
33}
34
35// pop remove last item as first output
36func (ll *Stack) Pop() any {

Callers 2

TestStackLinkedListFunction · 0.95
TestStackArrayFunction · 0.95

Calls

no outgoing calls

Tested by 2

TestStackLinkedListFunction · 0.76
TestStackArrayFunction · 0.76