2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
#ifndef STACKLST_HPP
|
|
|
|
#define STACKLST_HPP
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "../stack.hpp"
|
|
|
|
#include "../../list/list.hpp"
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
namespace lasd {
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-04-12 22:04:22 +02:00
|
|
|
class StackLst : virtual public Stack<Data>,
|
|
|
|
virtual protected List<Data> { // Must extend Stack<Data> and List<Data>
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2021-04-12 22:04:22 +02:00
|
|
|
using List<Data>::head;
|
|
|
|
using List<Data>::size;
|
|
|
|
using typename List<Data>::Node;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Default constructor
|
2021-04-12 22:04:22 +02:00
|
|
|
StackLst() = default;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific constructor
|
2021-04-12 22:04:22 +02:00
|
|
|
StackLst(const LinearContainer<Data>&); // A stack obtained from a LinearContainer
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy constructor
|
2021-04-12 22:04:22 +02:00
|
|
|
StackLst(const StackLst&);
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Move constructor
|
2021-04-12 22:04:22 +02:00
|
|
|
StackLst(StackLst&&) noexcept;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Destructor
|
2021-04-12 22:04:22 +02:00
|
|
|
virtual ~StackLst();
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
2021-04-12 22:04:22 +02:00
|
|
|
StackLst& operator=(const StackLst&);
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-04-12 22:04:22 +02:00
|
|
|
StackLst& operator=(StackLst&&) noexcept;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-04-12 22:04:22 +02:00
|
|
|
bool operator==(const StackLst&) const noexcept;
|
|
|
|
bool operator!=(const StackLst&) const noexcept;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from Stack)
|
|
|
|
|
2021-04-12 22:04:22 +02:00
|
|
|
void Push(const Data&) override; // Override Stack member (copy of the value)
|
|
|
|
void Push(Data&&) noexcept 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-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from Container)
|
|
|
|
|
2021-04-12 22:04:22 +02:00
|
|
|
void Clear() override; // Override Container member
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "stacklst.cpp"
|
|
|
|
|
|
|
|
#endif
|