view algs4-c++/src/Queue.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 b02533162b6e
children eb159ea69f33
line source
1 #ifndef QUEUE_HPP
2 #define QUEUE_HPP
4 #include <cstddef>
6 // Linked list based queue after Sedgewick and Wayne, Algorithms 4th ed, Algorithm 1.3
8 template <typename T>
9 class Queue {
11 private:
13 ////////////////////////////////////
14 class Node {
15 public:
16 T item;
17 Node *next;
18 };
20 public:
22 ////////////////////////////////////
23 class iterator;
24 friend class iterator;
25 class iterator {
27 public:
29 iterator( Node *c );
31 iterator& operator++();
32 iterator operator++(int);
34 T operator*();
35 bool operator!=( typename Queue<T>::iterator );
37 private:
39 Node *curr;
40 };
42 ////////////////////////////////////
44 Queue( void );
45 ~Queue( void );
47 void enqueue( T &item );
48 T dequeue( void );
50 bool is_empty( void );
51 size_t size( void );
53 iterator begin( void );
54 iterator end( void );
57 private:
59 size_t N;
60 Node *first;
61 Node *last;
63 };
67 #endif