From 419320e6ecb4dc420ff26827159e09a447f87c8e Mon Sep 17 00:00:00 2001 From: glazirEgorGeekovich Date: Sun, 25 May 2025 11:46:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- List.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 List.cpp diff --git a/List.cpp b/List.cpp new file mode 100644 index 0000000..dddccba --- /dev/null +++ b/List.cpp @@ -0,0 +1,114 @@ +#include "List.hpp" + + +// Components +// unNode +components::unNode::unNode() { + this->p_next = nullptr; + this->value = 0; +} + + + + +// Skeleton + +tls::Size strs::Skeleton::get_size() { + return this->size; +} + +void strs::Skeleton::pop() { + if (this->size == 0) return; + else if (this->first_element->p_next == nullptr){ + delete first_element; + first_element = nullptr; + } + if (this->first_element->p_next != nullptr){ + components::unNode *tmp = this->first_element->p_next; + delete first_element; + first_element = tmp; + } + --(this->size); +} + + + + + +// unarList +strs::unarList::unarList(){ + this->first_element = nullptr; + this->last_element = nullptr; + this->size = 0; +} + +void strs::unarList::pop() { + if (this->first_element->p_next != nullptr){ + components::unNode *tmp = this->first_element->p_next; + delete first_element; + first_element = tmp; + } +} + +void strs::unarList::remove(){ + components::unNode *tmp = this->first_element; + while (tmp->p_next->p_next != nullptr) tmp = tmp->p_next; + tmp->p_next = nullptr; + delete last_element; + last_element = tmp; + --(this->size); +} + +void strs::unarList::term() { + components::unNode *iter_node = first_element; + for (tls::Index i = 0; i < size; i++){ + std::cout<< iter_node->value << '\t' << iter_node << "\t point on: " << iter_node->p_next << std::endl; + iter_node = iter_node->p_next; + } + std::cout << "-------------------------------------------------------------" << std::endl; +} + +void strs::unarList::append(tls::Value new_value) { + this->last_element->p_next = new components::unNode; + this->last_element = this->last_element->p_next; + this->last_element->value = new_value; + ++(this->size); +} + + + + +components::unNode strs::unarList::operator() (tls::Size get_size){ + size = get_size; + components::unNode *iter_node = first_element; + for (tls::Index i = 0; i < size-1; i++){ + iter_node->p_next = new components::unNode; + iter_node = iter_node->p_next; + iter_node->value = i+1; + } + last_element = iter_node; + return *first_element; + +} + +components::unNode& strs::unarList::operator[] (tls::Index index){ + components::unNode *tmp = this->first_element; + for (int j = 0; j < index; j++){ + tmp = tmp->p_next; + } + return *tmp; +} + + + + + + + + + + + + + +