Skip to content

Instantly share code, notes, and snippets.

@oludouglas
Created September 15, 2020 12:48
Show Gist options
  • Save oludouglas/7fae2b64aa3eaad4cab3aac730a007db to your computer and use it in GitHub Desktop.
Save oludouglas/7fae2b64aa3eaad4cab3aac730a007db to your computer and use it in GitHub Desktop.
package interviews
type Queue struct {
values []interface{}
}
func (q *Queue) IsEmpty() bool {
return len(q.values) == 0
}
func (q *Queue) Size() int {
return len(q.values)
}
func (q *Queue) Enqueue(item interface{}) {
q.values = append(q.values, item)
}
func (q *Queue) Dequeue() interface{} {
if q.IsEmpty() {
return nil
}
v := q.values[0]
q.values = q.values[1:]
return v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment