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

Method Pop

structure/stack/stackarray.go:46–55  ·  view source on GitHub ↗

Pop removes and returns the top element from the stack.

()

Source from the content-addressed store, hash-verified

44
45// Pop removes and returns the top element from the stack.
46func (s *Array[T]) Pop() T {
47 if s.IsEmpty() {
48 var zeroValue T
49 return zeroValue // Stack is empty
50 }
51 index := len(s.elements) - 1
52 popped := s.elements[index]
53 s.elements = s.elements[:index]
54 return popped
55}

Callers

nothing calls this directly

Calls 1

IsEmptyMethod · 0.95

Tested by

no test coverage detected