-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.h
89 lines (54 loc) · 2.5 KB
/
stack.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// =======================================================
// Ashley Jacobs
// Compiler: g++
// Header file stack.h
//=======================================================
//----- Globally setting up the aliases ----------------
const int MAX = 10; // The MAX number of elements for the stack
// MAX is unknown to the client
typedef int el_t; // the el_t type is ** for now
// el_t is unknown to the client
//-------------------------------------------------------
class stack
{
private: // to be hidden from the client
el_t el[MAX]; // el is an array of el_t's
int top; // top is index to the top of stack
public: // available to the client
// Add exception handling classes here
class Underflow{};
class Overflow{};
// prototypes to be used by the client
// Note that no parameter variables are given
stack(); // constructor to create an object
~stack(); // destructor to destroy an object
// PURPOSE: if not full, enters an element at the top;
// otherwise throws an exception - Overflow
// PARAMETER: pass the element to be pushed
void push(el_t);
// PURPOSE: if not empty, removes and gives back the top element;
// otherwise throws an exception - Underflow
// PARAMETER: provide variable to receive the popped element (by ref)
void pop(el_t&);
// PURPOSE: if not empty, gives the top element without removing it;
// otherwise, throws an exception - Underflow
// PARAMETER: ** provides a variable to receive the value of the top element (by ref)
void topElem(el_t&);
// ** Must add good comments for each function - See Notes1B
//PURPOSE: ** if a given stack is empty, returns true
// if not, returns false
//NOTES: used in the pop function, no parameter
bool isEmpty();
//PURPOSE: ** if a given stack is full, returns true
// if not, returns false
//NOTES: used in the push function, no parameter
bool isFull();
//PURPOSE: ** if not empty, displays all elements (vertically from top to bottom)
// otherwise, throws an exception - Stack is empty
//NOTES: no parameter
void displayAll();
//PURPOSE: ** if not empty, removes all elements and decrements top
// else, throws an exception - Stack is empty
//NOTES: no parameter
void clearIt();
};