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

Method Pop

structure/stack/stacklinkedlist.go:36–46  ·  view source on GitHub ↗

pop remove last item as first output

()

Source from the content-addressed store, hash-verified

34
35// pop remove last item as first output
36func (ll *Stack) Pop() any {
37 result := ll.top.Val
38 if ll.top.Next == nil {
39 ll.top = nil
40 } else {
41 ll.top.Val, ll.top.Next = ll.top.Next.Val, ll.top.Next.Next
42 }
43
44 ll.length--
45 return result
46}
47
48// isEmpty to check our array is empty or not
49func (ll *Stack) IsEmpty() bool {

Callers 2

TestStackLinkedListFunction · 0.95
TestStackArrayFunction · 0.95

Calls

no outgoing calls

Tested by 2

TestStackLinkedListFunction · 0.76
TestStackArrayFunction · 0.76