MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / Pop

Method Pop

structure/stack/stacklinkedlistwithlist.go:38–48  ·  view source on GitHub ↗

Pop is return last value that insert into our stack also it will remove it in our stack

()

Source from the content-addressed store, hash-verified

36// Pop is return last value that insert into our stack
37// also it will remove it in our stack
38func (sl *SList) Pop() (any, error) {
39 if !sl.IsEmpty() {
40 // get last element that insert into stack
41 element := sl.Stack.Front()
42 // remove element in stack
43 sl.Stack.Remove(element)
44 // return element value
45 return element.Value, nil
46 }
47 return "", fmt.Errorf("stack list is empty")
48}
49
50// Length return length of our stack
51func (sl *SList) Length() int {

Callers 1

Calls 3

IsEmptyMethod · 0.95
FrontMethod · 0.45
RemoveMethod · 0.45

Tested by 1