doc PIMap PIStack PIQueue done

This commit is contained in:
Бычков Андрей
2022-09-02 09:44:47 +03:00
parent db3de9904a
commit eddef26b5e
4 changed files with 100 additions and 20 deletions

View File

@@ -37,18 +37,77 @@
#include "pideque.h"
#include "pivector.h"
//! \addtogroup Containers
//! \{
//! \class PIQueue
//! \brief
//! \~english A container class inherited from the \a PIDeque with queue functionality.
//! \~russian Класс контейнера наследованый от \a PIDeque с функциональностью очереди.
//! \~\}
//! \details
//! \~english The container is a array of elements organized according to the FIFO principle (first in, first out).
//! Adds \a enqueue() and \dequeue() functions to \a PIDeque.
//! \~russian Контейнер представляющий массив элементов, организованных по принципу FIFO (первым пришёл — первым вышел).
//! Добавляет к \a PIDeque функции \a enqueue() и \a dequeue().
//! \~\sa \a PIDeque
template<typename T>
class PIQueue: public PIDeque<T> {
public:
//! \~english Constructs an empty array.
//! \~russian Создает пустой массив.
PIQueue() {}
//! \~english Puts an element on the queue.
//! \~russian Кладёт элемент в очередь.
PIDeque<T> & enqueue(const T & v) {PIDeque<T>::push_front(v); return *this;}
//! \~english Move an element on the queue.
//! \~russian Перемещает элемент в очередь.
PIDeque<T> & enqueue(T && v) {PIDeque<T>::push_front(std::move(v)); return *this;}
//! \~english Retrieves and returns an element from the queue.
//! \~russian Забирает и возвращает элемент из очереди.
//! \~\details
//! \note
//! \~english This function assumes that the array isn't empty.
//! Otherwise will be undefined behavior.
//! \~russian Эта функция предполагает, что массив не пустой.
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
T dequeue() {return PIDeque<T>::take_back();}
//! \~english Head element of the queue.
//! \~russian Головной (верхний) элемент очереди.
//! \~\details
//! \note
//! \~english Returns a reference to the head element of the queue.
//! This function assumes that the array isn't empty.
//! Otherwise will be undefined behavior.
//! \~russian Возвращает ссылку на головной (верхний) элемент очереди.
//! Эта функция предполагает, что массив не пустой.
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
T & head() {return PIDeque<T>::back();}
const T & head() const {return PIDeque<T>::back();}
PIVector<T> toVector() {return PIVector<T>(PIDeque<T>::data(), PIDeque<T>::size());}
PIDeque<T> toDeque() {return PIDeque<T>(*this);}
//! \~english Tail element of the queue.
//! \~russian Хвостовой (нижний) элемент очереди.
//! \~\details
//! \~english Returns a reference to the tail element of the queue.
//! This function assumes that the array isn't empty.
//! Otherwise will be undefined behavior.
//! \~russian Возвращает ссылку на хвостовой (нижний) элемент очереди.
//! Эта функция предполагает, что массив не пустой.
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
T & tail() {return PIDeque<T>::front();}
const T & tail() const {return PIDeque<T>::front();}
//! \~english Converts \a PIQueue to \a PIVector.
//! \~russian Преобразует \a PIQueue в \a PIVector.
PIVector<T> toVector() const {return PIVector<T>(PIDeque<T>::data(), PIDeque<T>::size());}
//! \~english Converts \a PIQueue to \a PIDeque.
//! \~russian Преобразует \a PIQueue в \a PIDeque.
PIDeque<T> toDeque() const {return PIDeque<T>(*this);}
};
#endif // PIQUEUE_H