Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created July 2, 2012 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim-smart/3424338ddfd0c9f173e3 to your computer and use it in GitHub Desktop.
Save tim-smart/3424338ddfd0c9f173e3 to your computer and use it in GitHub Desktop.
function Queue:initialize()
self.tail = 0
self.head = 1
end
function Queue:push(value)
self.tail = self.tail + 1
self[self.tail] = value
end
function Queue:pop()
local head = self.head
local tail = self.tail
local value = self[head]
self[head] = nil
self.head = head + 1
if self.head > self.tail then
self.head = 1
self.tail = 0
end
return value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment