Mercurial > Algorithms__Sedgewick
view algs4-c++/src/Deque.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 DEQUE_HPP
2 #define DEQUE_HPP
4 #include <cstddef>
6 // Linked list based deque after Sedgewick and Wayne, Algorithms 4th ed, Algorithm 1.3
8 template <typename T>
9 class Deque {
11 private:
13 ////////////////////////////////////
14 class Node {
15 public:
16 T item;
17 Node *next;
18 Node *prev;
19 };
21 public:
23 ////////////////////////////////////
24 class iterator;
25 friend class iterator;
26 class iterator {
28 public:
30 iterator( Node *c );
32 iterator& operator++();
33 iterator operator++(int);
35 T operator*();
36 bool operator!=( typename Deque<T>::iterator );
38 private:
40 Node *curr;
41 };
43 ////////////////////////////////////
45 Deque( void );
46 ~Deque( void );
48 void push_left( T &item );
49 void push_right( T &item );
50 T pop_left( void );
51 T pop_right( void );
53 bool is_empty( void );
54 size_t size( void );
56 iterator begin( void );
57 iterator end( void );
60 private:
62 size_t N;
63 Node *first;
64 Node *last;
66 };
70 #endif