Created
September 15, 2020 12:48
-
-
Save oludouglas/7fae2b64aa3eaad4cab3aac730a007db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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