-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharraystack.h
More file actions
41 lines (32 loc) · 982 Bytes
/
arraystack.h
File metadata and controls
41 lines (32 loc) · 982 Bytes
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
33
34
35
36
37
38
39
40
41
#ifndef ARRAYSTACK_H
#define ARRAYSTACK_H
#include <string>
#include <exception>
using namespace std;
class RuntimeException { // generic run-time exception private:
string errorMsg; public:
RuntimeException(const string& err) { errorMsg = err; }
string getMessage() const { return errorMsg; } };
class StackEmpty : public RuntimeException {
public:
StackEmpty(const string& err) : RuntimeException(err) {} };
class StackFull : public RuntimeException {
public:
StackFull(const string& err) : RuntimeException(err) {} };
template <typename E>
class ArrayStack {
enum { DEF_CAPACITY = 100 };
public:
// default stack capacity
ArrayStack(int cap = DEF_CAPACITY);
~ArrayStack();
int size() const;
bool empty() const;
const E& top() const throw(StackEmpty); // get the top element
void push(const E& e) throw(StackFull);
void pop() throw(StackEmpty);
private:
E* S;
int capacity; int t;
};
#endif // ARRAYSTACK_H