diff --git a/StackV.h b/StackV.h index 765dade..b54f90f 100644 --- a/StackV.h +++ b/StackV.h @@ -1,3 +1,4 @@ + //Implementing a Stack ADT with a vector #ifndef STACK_H @@ -6,11 +7,12 @@ #include using namespace std; +template class Stack { private: - vector data; + vector data; public: @@ -22,15 +24,26 @@ class Stack // No d'tor needs to be declared // The vector "knows" how to destroy itself - int size(); - - void push(int); - - void pop(); - - int top(); - - void clear(); + int size() const { return data.size(); } + + void push(const T& data) + { + this->data.push_back(data); + } + void pop() + { + this->data.pop_back(); + } + + // returns the data at the top of the stack + int top() const + { + return this->data.at(data.size() - 1); + } + void clear() + { + this->data.clear(); + } };