-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric_stack.hh
32 lines (27 loc) · 986 Bytes
/
generic_stack.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <ostream>
namespace generic_stack {
class GenericStack {
public:
GenericStack(void *arr, int size) : size_(size), arr_(arr), top_(0){};
GenericStack(const GenericStack &astack)
: size_(astack.size_), arr_(astack.arr_), top_(astack.top_){};
// These functions could be implemented as operator+() and operator-(), but
// that seems unnatural.
// Generic versions won't compile.
// void Push(void *datum);
// void *Pop();
// With no templates, each stack type needs its own operators.
void DoublePush(double datum);
double DoublePop();
friend ::std::ostream &operator<<(::std::ostream &out,
const GenericStack &astack);
bool full() const { return top_ == (size_ - 1); }
bool empty() const { return 0 == top_; }
private:
int size_;
void *arr_;
int top_;
};
::std::ostream &operator<<(::std::ostream &out, const GenericStack &astack);
void Reverse(double data[], int size);
} // namespace generic_stack