view algs4-c++/src/Steque.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 STEQUE_HPP
2 #define STEQUE_HPP
4 #include <cstddef>
6 // Linked list based steque after Sedgewick and Wayne, Algorithms 4th ed, Algorithm 1.2
8 template <typename T>
9 class Steque {
11 private:
13 ////////////////////////////////////
14 class Node {
15 public:
16 T item;
17 Node *next;
18 };
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 Steque<T>::iterator );
38 private:
40 Node *curr;
41 };
43 ////////////////////////////////////
45 Steque( void );
46 ~Steque( void );
48 void push( T &item );
49 T pop( void );
50 void enqueue( T &item );
52 bool is_empty( void );
53 size_t size( void );
55 iterator begin( void );
56 iterator end( void );
58 private:
60 size_t N;
61 Node *list;
63 };
67 #endif