Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct deque
- {
- int* values;
- int start;
- int end;
- int capacity;
- int size;
- deque(int size)
- {
- capacity = size;
- values = new int[capacity];
- start = 0;
- end = 0;
- size = 0;
- }
- void push_front(int item)
- {
- values[start] = item;
- start = (start + 1) % capacity;
- size++;
- }
- void push_back(int item)
- {
- values[end] = item;
- end = (end - 1 + capacity) % capacity;
- size++;
- }
- void pop_front(void)
- {
- start = (start - 1 + capacity) % capacity;
- size--;
- }
- void pop_end(void)
- {
- end = (end + 1) % capacity;
- size--;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement