Mercurial > Algorithms__Sedgewick
view algs4-c++/src/ResizingArrayDeque.hpp @ 15:63df3e6590e2
Bag and RandomBag (1.3.34) classes.
There are not really robust enough to use as they will leak memory on
destruction if you use them to store dynamically allocated objects.
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Thu, 11 Jun 2015 16:30:14 -0500 |
parents | |
children | a149b424b4e2 |
line source
1 #ifndef RESIZINGARRAYDEQUE_HPP
2 #define RESIZINGARRAYDEQUE_HPP
4 #include <cstddef>
6 template <typename T>
7 class ResizingArrayDeque {
9 public:
11 ////////////////////////////////////////
12 class iterator {
14 public:
16 iterator( T *c, T *l, T *b, T *m );
18 iterator& operator++();
19 iterator operator++(int);
21 T operator*();
22 bool operator!=( typename ResizingArrayDeque<T>::iterator );
24 private:
26 T *curr;
27 T *last;
28 T *begin;
29 T *max;
30 };
32 ////////////////////////////////////////
33 ResizingArrayDeque( void );
34 ~ResizingArrayDeque( void );
36 void push_left( T &item );
37 void push_right( T &item );
38 T pop_left( void );
39 T pop_right( void );
41 bool is_empty( void );
42 size_t size( void );
44 iterator begin( void );
45 iterator end( void );
47 private:
49 size_t N;
50 size_t max;
51 T *first, *last;
52 T *data;
54 void resize( size_t new_max );
55 };
59 #endif