Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. var max:Int!
  2. var data:[Any] = []
  3.  
  4. init(_ max:Int) {
  5. self.max = max
  6. }
  7.  
  8. func enqueue(_ obj:Any) -> Bool {
  9. if data.count > self.max - 1 {
  10. return false
  11. }
  12. data.append(obj)
  13. return true
  14. }
  15.  
  16. func dequeue() -> Any? {
  17. if data.count > 0 {
  18. let obj = data[0]
  19. data.remove(at: 0)
  20. return obj
  21. }
  22. return nil
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement