Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _STACK
- #define _STACK
- template <class T>
- class Stack {
- public:
- Stack();
- Stack(const int &num);
- Stack(const Stack<T> &obj);
- Stack& operator=(const Stack<T> &obj);
- ~Stack();
- private:
- T * buffer;
- unsigned int actualSize;
- unsigned int maxSize;
- };
- template <class T>
- Stack<T>::Stack() : maxSize(5), actualSize(0), buffer(new T[5]) {};
- template <class T>
- Stack<T>::Stack(const int &num) : maxSize(num), actualSize(num), buffer(new T[num]) {};
- template <class T>
- Stack<T>::Stack(const Stack<T> &obj) {
- this->actualSize = obj.actualSize;
- this->maxSize = obj.maxSize;
- std::copy(obj.buffer, obj.buffer + obj.actualSize, this->buffer);
- }
- template <class T>
- Stack<T>& Stack<T>::operator=(const Stack<T> &obj) {
- T * temp = new T[obj.actualSize];
- std::copy(obj.buffer, obj.buffer + obj.actualSize, temp);
- this->actualSize = obj.actualSize;
- this->maxSize = obj.maxSize;
- delete[] buffer;
- buffer = temp;
- return *this;
- }
- template <class T>
- Stack<T>::~Stack() {
- delete[] buffer;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement