()
| 26 | q.primary.Push(data) |
| 27 | } |
| 28 | func (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 | |
| 40 | func (q *MyQueue) Len() int { |
| 41 | return q.primary.Len() + q.buffer.Len() |