MCPcopy Create free account
hub / github.com/careercup/ctci / DeQueue

Method DeQueue

Go/Chapter 3/Question3_5/Question.go:28–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 q.primary.Push(data)
27}
28func (q *MyQueue) DeQueue() (int, error) {
29 if (q.primary.Len() == 0 && q.buffer.Len() == 0) {
30 return 0, errors.New("Queue is empty")
31 }
32 /* Push all primary elems to buffer and pop the last elem from buffer */
33 for (q.primary.Len() > 0) {
34 val, _ := q.primary.Pop()
35 q.buffer.Push(val)
36 }
37 return q.buffer.Pop()
38}
39
40func (q *MyQueue) Len() int {
41 return q.primary.Len() + q.buffer.Len()

Callers 1

mainFunction · 0.95

Calls 3

LenMethod · 0.45
PopMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected