view algs4-c++/src/ResizingArrayStack.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 ca59e5f5b29e
children a149b424b4e2
line source
1 #ifndef RESIZINGARRAYSTACK_HPP
2 #define RESIZINGARRAYSTACK_HPP
4 #include <cstddef>
6 template <typename T>
7 class ResizingArrayStack {
9 public:
11 ResizingArrayStack( void );
12 ~ResizingArrayStack( void );
14 void push( T &item );
15 T pop( void );
17 bool is_empty( void );
18 size_t size( void );
20 class iterator;
21 friend class iterator;
22 class iterator {
24 public:
26 iterator( T *c, T *e );
28 iterator& operator++();
29 iterator operator++(int);
31 T operator*();
32 bool operator!=( typename ResizingArrayStack<T>::iterator );
34 private:
36 T *curr;
37 T *end;
38 };
40 iterator begin( void );
41 iterator end( void );
43 private:
45 size_t N;
46 size_t max;
47 T *data;
49 void resize( size_t new_max );
50 };
54 #endif