#ifndef _intstack_h_
#define _intstack_h_
#include <cstddef>
// Implements a stack of integers.
class IntStack {
private:
// Stack node type.
struct StackNode {
StackNode(int d, StackNode *n) {
data = d;
next = n;
}
int data;
StackNode *next;
};
// Head of the stack
StackNode *head;
// This forbids copying and assigning stacks.
IntStack(const IntStack &) = delete;
IntStack & operator = (const IntStack &) = delete;
public:
// Must make sure stack is empty at construct.
IntStack() {
head = NULL;
}
// Make sure the stack is cleaned up at exit.
~IntStack() {
clear();
}
// Push onto the stack.
void push(int i) {
head = new StackNode(i, head);
}
// Remove from the stack.
int pop();
// Find out what's on the top.
int top() const {
if(head == NULL)
return 0;
else
return head->data;
}
// So, are we empty yet?
bool isEmpty() const {
return head == NULL;
}
// Remove all memory from the stack.
void clear();
};
#endif