Advertisement
Guest User

Code

a guest
Oct 9th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. struct deque
  2. {
  3. int* values;
  4. int start;
  5. int end;
  6. int capacity;
  7. int size;
  8.  
  9. deque(int size)
  10. {
  11. capacity = size;
  12. values = new int[capacity];
  13. start = 0;
  14. end = 0;
  15. size = 0;
  16. }
  17.  
  18. void push_front(int item)
  19. {
  20. values[start] = item;
  21. start = (start + 1) % capacity;
  22. size++;
  23. }
  24.  
  25. void push_back(int item)
  26. {
  27. values[end] = item;
  28. end = (end - 1 + capacity) % capacity;
  29. size++;
  30. }
  31.  
  32. void pop_front(void)
  33. {
  34. start = (start - 1 + capacity) % capacity;
  35. size--;
  36. }
  37.  
  38.  
  39. void pop_end(void)
  40. {
  41. end = (end + 1) % capacity;
  42. size--;
  43. }
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement