136 Chapter 7
41 * Also if you don't empty a stack *
42 * before you're finished, an exception *
43 * is thrown. *
44 ************************************************/
45 class stack {
46 private:
47 // The stack's data
48 int data[MAX_DATA];
49
50 // Number of elements
51 // currently in the stack
52 int count;
53
54 public:
55 // Constructor
56 stack(void) : count(0) {};
57
58 // Destructor -- Check for non
59 ~stack(void)
60 {
61 if (count != 0)
62 {
63 throw(
64 problem("Stack not empty"));
65 }
66 }
67
68 // Push an item on the stack
69 void push(
70 const int what // Item to store
71 )
72 {
73 data[count] = what;
74 ++count;
75 }
76 // Remove an item from the stack
77 int pop(void)
78 {
79 if (count == 0)
80 throw(
81 problem("Stack underflow"));
82 --count;
83 return (data[coun ...