2020-07-23 21:58:18 +00:00
|
|
|
/*#############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
|
|
|
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
|
2020-07-24 20:55:36 +00:00
|
|
|
## About: An example of a vector implementation using templates ##
|
2020-07-23 21:58:18 +00:00
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################
|
|
|
|
## vector.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VECTOR_H
|
|
|
|
#define VECTOR_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Vector {
|
|
|
|
public:
|
|
|
|
Vector() : maxSize(0), curIndex(-1), data(NULL) {};
|
|
|
|
Vector(const Vector& rhs);
|
|
|
|
Vector<T> operator=(Vector<T> rhs);
|
|
|
|
~Vector();
|
|
|
|
bool push(T val);
|
|
|
|
T pop();
|
|
|
|
void makeEmpty();
|
|
|
|
T peek() const;
|
|
|
|
bool isEmpty() const;
|
|
|
|
bool isFull() const;
|
|
|
|
void print() const;
|
2020-07-24 20:55:36 +00:00
|
|
|
int getMax() const;
|
|
|
|
int getSize() const;
|
|
|
|
int getIndex() const;
|
|
|
|
T getValue(int index) const;
|
2020-07-23 21:58:18 +00:00
|
|
|
|
|
|
|
private:
|
2020-07-24 20:55:36 +00:00
|
|
|
int maxSize;
|
|
|
|
int curIndex;
|
2020-07-23 21:58:18 +00:00
|
|
|
T *data;
|
|
|
|
bool push(T val, T *&data);
|
|
|
|
T pop(T *&data);
|
|
|
|
void makeEmpty(T *&data);
|
|
|
|
T peek(T *data) const;
|
|
|
|
void print(T *data) const;
|
|
|
|
};
|
|
|
|
|
2020-07-24 20:55:36 +00:00
|
|
|
|
2020-07-23 21:58:18 +00:00
|
|
|
#endif
|