Mercurial > Algorithms__Sedgewick
comparison algs4-c++/src/Deque.hpp @ 12:1e3c509b6ac4
Added Deque (exercise 1.3.33)
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Wed, 10 Jun 2015 15:44:42 -0500 |
parents | |
children | a149b424b4e2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:58225eb10c33 |
---|---|
1 #ifndef DEQUE_HPP | |
2 #define DEQUE_HPP | |
3 | |
4 #include <cstddef> | |
5 | |
6 // Linked list based deque after Sedgewick and Wayne, Algorithms 4th ed, Algorithm 1.3 | |
7 | |
8 template <typename T> | |
9 class Deque { | |
10 | |
11 private: | |
12 | |
13 //////////////////////////////////// | |
14 class Node { | |
15 public: | |
16 T item; | |
17 Node *next; | |
18 Node *prev; | |
19 }; | |
20 | |
21 public: | |
22 | |
23 //////////////////////////////////// | |
24 class iterator; | |
25 friend class iterator; | |
26 class iterator { | |
27 | |
28 public: | |
29 | |
30 iterator( Node *c ); | |
31 | |
32 iterator& operator++(); | |
33 iterator operator++(int); | |
34 | |
35 T operator*(); | |
36 bool operator!=( typename Deque<T>::iterator ); | |
37 | |
38 private: | |
39 | |
40 Node *curr; | |
41 }; | |
42 | |
43 //////////////////////////////////// | |
44 | |
45 Deque( void ); | |
46 ~Deque( void ); | |
47 | |
48 void push_left( T &item ); | |
49 void push_right( T &item ); | |
50 T pop_left( void ); | |
51 T pop_right( void ); | |
52 | |
53 bool is_empty( void ); | |
54 size_t size( void ); | |
55 | |
56 iterator begin( void ); | |
57 iterator end( void ); | |
58 | |
59 | |
60 private: | |
61 | |
62 size_t N; | |
63 Node *first; | |
64 Node *last; | |
65 | |
66 }; | |
67 | |
68 | |
69 | |
70 #endif | |
71 |