Advertisement
Guest User

Untitled

a guest
May 25th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. function New()
  2. local queue = {}
  3. queue._frontIndex = 1
  4. queue.Size = 0
  5. return queue
  6. end
  7.  
  8. function Enqueue(queue, item)
  9. queue[queue._frontIndex + queue.Size] = item
  10. queue.Size = queue.Size + 1
  11. end
  12.  
  13. function Dequeue(queue)
  14. if (queue.Size == 0) then
  15. return nil
  16. end
  17.  
  18. local item = queue[queue._frontIndex]
  19. queue[queue._frontIndex] = nil
  20. queue._frontIndex = queue._frontIndex + 1
  21. queue.Size = queue.Size - 1
  22. return item
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement