Advertisement
Guest User

Untitled

a guest
May 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Queue {
  2. constructor() {
  3. this._start = 0;
  4. this._end = 0;
  5. this._storage = {};
  6. }
  7.  
  8. enqueue(value) {
  9. this._storage[this._end] = value;
  10. this._end ++;
  11. }
  12.  
  13. dequeue() {
  14. if (this._size()) {
  15. var dequeued = this._storage[this._start];
  16. delete this._storage[this._start];
  17. this._start ++;
  18. return dequeued;
  19. }
  20. return 'The Queue is empty';
  21. }
  22.  
  23. _size() {
  24. return this._end - this._start;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement