mirror of
https://github.com/xfarrow/lasd.git
synced 2025-02-16 12:10:37 +01:00
Library 2
implemented stacklist
This commit is contained in:
parent
c30aaf96c9
commit
1100ac3b56
@ -129,7 +129,7 @@ bool List<Data>::operator!=(const List<Data>& list) const noexcept{
|
|||||||
void List<Data>::InsertAtFront(Data&& data){
|
void List<Data>::InsertAtFront(Data&& data){
|
||||||
struct Node* tmp = new Node(data);
|
struct Node* tmp = new Node(data);
|
||||||
tmp->next = head;
|
tmp->next = head;
|
||||||
head =tmp;
|
head=tmp;
|
||||||
size++;
|
size++;
|
||||||
|
|
||||||
if(size == 1){
|
if(size == 1){
|
||||||
|
@ -3,7 +3,85 @@ namespace lasd {
|
|||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
// ...
|
// Constructors
|
||||||
|
template <typename Data>
|
||||||
|
StackLst(const LinearContainer<Data>& linear){
|
||||||
|
for(ulong i=linear.Size()-1 ; i>=0 ; --i){ // è possibile usare il costruttore di List?
|
||||||
|
Push(linear[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StackLst(const StackLst& stcklist){
|
||||||
|
for(ulong i=stcklist.Size()-1 ; i>=0 ; --i){
|
||||||
|
Push(stcklist[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
StackLst<Data>::StackLst(StackLst&& stcklist) noexcept{
|
||||||
|
std::swap(size, stcklist.size);
|
||||||
|
std::swap(head, stcklist.head);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
virtual ~StackLst(){
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
StackLst& operator=(const StackLst& copyFrom){
|
||||||
|
if(*this != copyFrom){
|
||||||
|
Clear();
|
||||||
|
for(ulong i=copyFrom.Size()-1 ; i>=0 ; --i){
|
||||||
|
Push(copyFrom[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StackLst& operator=(StackLst&& moveFrom){
|
||||||
|
std::swap(size, moveFrom.size);
|
||||||
|
std::swap(head, moveFrom.head);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const StackLst& stcklist) const noexcept{
|
||||||
|
return List<Data>::operator==(stcklist);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const StackLst& stcklist) const noexcept{
|
||||||
|
return List<Data>::operator!=(stcklist);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Specific member functions (inherited from Stack)
|
||||||
|
template <typename Data>
|
||||||
|
void Push(const Data& element){
|
||||||
|
List<Data>::InsertAtFront(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
void Push(Data&& element){
|
||||||
|
List<Data>::InsertAtFront(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
Data& Top() const{
|
||||||
|
return List<Data>::Front();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
void Pop(){
|
||||||
|
List<Data>::RemoveFromFront();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
Data TopNPop(){
|
||||||
|
return List<Data>::FrontNRemove();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Data>
|
||||||
|
void Clear(){
|
||||||
|
List<Data>::Clear();
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -14,70 +14,69 @@ namespace lasd {
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class StackLst { // Must extend Stack<Data> and List<Data>
|
class StackLst : virtual public Stack<Data>,
|
||||||
|
virtual protected List<Data> { // Must extend Stack<Data> and List<Data>
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// using List<Data>::???;
|
using List<Data>::head;
|
||||||
|
using List<Data>::size;
|
||||||
// ...
|
using typename List<Data>::Node;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Default constructor
|
// Default constructor
|
||||||
// StackLst() specifier;
|
StackLst() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific constructor
|
// Specific constructor
|
||||||
// StackLst(argument) specifiers; // A stack obtained from a LinearContainer
|
StackLst(const LinearContainer<Data>&); // A stack obtained from a LinearContainer
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Copy constructor
|
// Copy constructor
|
||||||
// StackLst(argument);
|
StackLst(const StackLst&);
|
||||||
|
|
||||||
// Move constructor
|
// Move constructor
|
||||||
// StackLst(argument);
|
StackLst(StackLst&&) noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~StackLst() specifier;
|
virtual ~StackLst();
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument);
|
StackLst& operator=(const StackLst&);
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument);
|
StackLst& operator=(StackLst&&) noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers;
|
bool operator==(const StackLst&) const noexcept;
|
||||||
// type operator!=(argument) specifiers;
|
bool operator!=(const StackLst&) const noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from Stack)
|
// Specific member functions (inherited from Stack)
|
||||||
|
|
||||||
// type Push(argument) specifiers; // Override Stack member (copy of the value)
|
void Push(const Data&) override; // Override Stack member (copy of the value)
|
||||||
// type Push(argument) specifiers; // Override Stack member (move of the value)
|
void Push(Data&&) noexcept override; // Override Stack member (move of the value)
|
||||||
// type Top() specifiers; // Override Stack member (must throw std::length_error when empty)
|
Data& Top() const override; // Override Stack member (must throw std::length_error when empty)
|
||||||
// type Pop() specifiers; // Override Stack member (must throw std::length_error when empty)
|
void Pop() override; // Override Stack member (must throw std::length_error when empty)
|
||||||
// type TopNPop() specifiers; // Override Stack member (must throw std::length_error when empty)
|
Data TopNPop() override; // Override Stack member (must throw std::length_error when empty)
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from Container)
|
// Specific member functions (inherited from Container)
|
||||||
|
|
||||||
// type Clear() specifiers; // Override Container member
|
void Clear() override; // Override Container member
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,44 +13,40 @@ namespace lasd {
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class Stack { // Must extend Container
|
class Stack : virtual public Container { // Must extend Container
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~Stack() specifiers
|
virtual ~Stack() = default;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
Stack& operator=(const Stack&) = delete; // Copy assignment of abstract types should not be possible.
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
Stack&operator=(Stack&&) = delete; // Move assignment of abstract types should not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator==(const Stack&) = delete; // Comparison of abstract types might not be possible.
|
||||||
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
bool operator!=(Stack&&) = delete; // Comparison of abstract types might not be possible.
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions
|
// Specific member functions
|
||||||
|
|
||||||
// type Push(argument) specifiers; // Copy of the value
|
virtual void Push(const Data&) = 0; // Copy of the value
|
||||||
// type Push(argument) specifiers; // Move of the value
|
virtual void Push(Data&&) = 0; // Move of the value
|
||||||
// type Top() specifiers; // (concrete function must throw std::length_error when empty)
|
virtual Data& Top() const = 0; // (concrete function must throw std::length_error when empty)
|
||||||
// type Pop() specifiers; // (concrete function must throw std::length_error when empty)
|
virtual void Pop() = 0; // (concrete function must throw std::length_error when empty)
|
||||||
// type TopNPop() specifiers; // (concrete function must throw std::length_error when empty)
|
virtual Data TopNPop() = 0; // (concrete function must throw std::length_error when empty)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,81 +14,81 @@ namespace lasd {
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
class StackVec { // Must extend Stack<Data> and Vector<Data>
|
class StackVec : virtual public Stack<Data>,
|
||||||
|
virtual protected Vector<Data>{ // Must extend Stack<Data> and Vector<Data>
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// using Vector<Data>::???;
|
ulong stackSize = 0; // Actual stack dimension
|
||||||
|
using Vector<Data>::Elements;
|
||||||
|
using Vector<Data>::size;
|
||||||
|
|
||||||
// ...
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Default constructor
|
// Default constructor
|
||||||
// StackVec() specifier;
|
StackVec();
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific constructor
|
// Specific constructor
|
||||||
// StackVec(argument) specifiers; // A stack obtained from a LinearContainer
|
StackVec(const LinearContainer<Data>&); // A stack obtained from a LinearContainer
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Copy constructor
|
// Copy constructor
|
||||||
// StackVec(argument);
|
StackVec(const StackVec&);
|
||||||
|
|
||||||
// Move constructor
|
// Move constructor
|
||||||
// StackVec(argument);
|
StackVec(StackVec&&) noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
// ~StackVec() specifier;
|
virtual ~StackVec();
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Copy assignment
|
// Copy assignment
|
||||||
// type operator=(argument);
|
StackVec& operator=(const StackVec&)
|
||||||
|
|
||||||
// Move assignment
|
// Move assignment
|
||||||
// type operator=(argument);
|
StackVec& operator=(StackVec&&) noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Comparison operators
|
// Comparison operators
|
||||||
// type operator==(argument) specifiers;
|
bool operator==(const StackVec&) const noexcept;
|
||||||
// type operator!=(argument) specifiers;
|
bool operator!=(const StackVec&) const noexcept;
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from Stack)
|
// Specific member functions (inherited from Stack)
|
||||||
|
|
||||||
// type Push(argument) specifiers; // Override Stack member (copy of the value)
|
void Push(const Data&) override; // Override Stack member (copy of the value)
|
||||||
// type Push(argument) specifiers; // Override Stack member (move of the value)
|
void Push(Data&&) override; // Override Stack member (move of the value)
|
||||||
// type Top() specifiers; // Override Stack member (must throw std::length_error when empty)
|
Data& Top() const override; // Override Stack member (must throw std::length_error when empty)
|
||||||
// type Pop() specifiers; // Override Stack member (must throw std::length_error when empty)
|
void Pop() override; // Override Stack member (must throw std::length_error when empty)
|
||||||
// type TopNPop() specifiers; // Override Stack member (must throw std::length_error when empty)
|
Data TopNPop() override; // Override Stack member (must throw std::length_error when empty)
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
// Specific member functions (inherited from Container)
|
// Specific member functions (inherited from Container)
|
||||||
|
|
||||||
// type Empty() specifiers; // Override Container member
|
bool Empty() const noexcept override; // Override Container member
|
||||||
|
|
||||||
// type Size() specifiers; // Override Container member
|
ulong Size() const noexcept override; specifiers; // Override Container member
|
||||||
|
|
||||||
// type Clear() specifiers; // Override Container member
|
void Clear() override;// Override Container member
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Auxiliary member functions
|
// Auxiliary member functions
|
||||||
|
|
||||||
// type Expand() specifiers;
|
void Expand();
|
||||||
// type Reduce() specifiers;
|
void Reduce();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user