Dequeue removes and returns the front element of the queue. It returns false if the queue was empty.
()
| 17 | |
| 18 | // Dequeue removes and returns the front element of the queue. It returns false if the queue was empty. |
| 19 | func (q *Queue[T]) Dequeue() (val T, ok bool) { |
| 20 | if q.IsEmpty() { |
| 21 | return |
| 22 | } |
| 23 | |
| 24 | val = q.data[0] |
| 25 | q.data = q.data[1:] |
| 26 | |
| 27 | return val, true |
| 28 | } |
| 29 | |
| 30 | // First returns the front element of the queue. It returns false if the queue was empty. |
| 31 | func (q *Queue[T]) First() (val T, ok bool) { |