2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
#ifndef STACKVEC_HPP
|
|
|
|
#define STACKVEC_HPP
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "../stack.hpp"
|
|
|
|
#include "../../vector/vector.hpp"
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
namespace lasd {
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class StackVec : virtual public Stack<Data>,
|
|
|
|
virtual protected Vector<Data>{ // Must extend Stack<Data> and Vector<Data>
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
ulong stackSize = 0; // first empty cell and # of elements in the vector
|
|
|
|
using Vector<Data>::Elements;
|
|
|
|
using Vector<Data>::size; // dimension of the vector
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Default constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
StackVec();
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
StackVec(const LinearContainer<Data>&); // A stack obtained from a LinearContainer
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
StackVec(const StackVec&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
StackVec(StackVec&&) noexcept;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~StackVec();
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
StackVec& operator=(const StackVec&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
StackVec& operator=(StackVec&&) noexcept;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const StackVec&) const noexcept;
|
|
|
|
bool operator!=(const StackVec&) const noexcept;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from Stack)
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void Push(const Data&) override; // Override Stack member (copy of the value)
|
|
|
|
void Push(Data&&) override; // Override Stack member (move of the value)
|
|
|
|
Data& Top() const override; // Override Stack member (must throw std::length_error when empty)
|
|
|
|
void Pop() override; // Override Stack member (must throw std::length_error when empty)
|
|
|
|
Data TopNPop() override; // Override Stack member (must throw std::length_error when empty)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from Container)
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
bool Empty() const noexcept override; // Override Container member
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
ulong Size() const noexcept override; // Override Container member
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void Clear() override;// Override Container member
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// Auxiliary member functions
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void Expand();
|
|
|
|
void Reduce();
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "stackvec.cpp"
|
|
|
|
|
|
|
|
#endif
|