Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions StackV.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//Implementing a Stack ADT with a vector

#ifndef STACK_H
Expand All @@ -6,11 +7,12 @@
#include <vector>
using namespace std;

template<typename T>
class Stack
{
private:

vector<int> data;
vector<T> data;


public:
Expand All @@ -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();
}

};

Expand Down