Last active
November 17, 2020 03:02
-
-
Save yefim/4063801 to your computer and use it in GitHub Desktop.
Queue implementation in CoffeeScript
This file contains 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
class Q | |
constructor: (@bound) -> | |
@offset = 0 | |
@length = 0 | |
@data = [] | |
enqueue: (value) -> | |
return undefined if @length == @bound | |
@data.push value | |
++@length | |
dequeue: -> | |
return undefined if !@length | |
value = @data[@offset] | |
@offset++ | |
@length-- | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment