Denied an approach inheritance

This commit is contained in:
glazirgeek 2025-05-25 18:59:00 +03:00
parent 3cf187a4ff
commit c6d800111c
2 changed files with 103 additions and 127 deletions

159
List.cpp
View file

@ -2,111 +2,84 @@
// Components
// unNode
components::unNode::unNode() {
// dualNode
components::dualNode::dualNode() {
this->p_next = nullptr;
this->p_prev = 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;
// Structures
strs::dualList::dualList(){
this->first_element = new components::dualNode;
this->last_element = this->first_element;
this->size = 1;
}
components::dualNode strs::dualList::operator() (tls::Size set_size){
this->size = set_size;
components::dualNode *iter_node = first_element;
for (tls::Index i = 0; i < size-1; i++){
iter_node->p_next = new components::dualNode;
iter_node->p_next->p_prev = iter_node;
iter_node = iter_node->p_next;
iter_node->value = 0;
}
--(this->size);
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;
//}
//
// 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;
//
//void strs::unarList::pop() {
// if (this->size == 0) return;
// if (this->first_element->p_next != nullptr){
// components::unNode *tmp = this->first_element->p_next;
// delete first_element;
// first_element = tmp;
// }
// else {
// delete first_element;
// first_element = nullptr;
// }
// --(this->size);
//}
//
//
//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::dualList::term() {
components::dualNode *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;
std::cout <<"previed by: " << iter_node->p_prev << '\t' << "value: " << iter_node->value << '\t' << "own &: "<< 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;
}
//
//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);
//}

View file

@ -3,64 +3,67 @@
#include <iostream>
#include "tools.hpp"
#include <strstream>
#include <sstream>
namespace components{
struct unNode{
unNode *p_next;;
unNode *p_next;
tls::Value value;
unNode();
};
struct dualNode:unNode {
tls::Value *p_prev;;
struct dualNode {
tls::Value value;
dualNode *p_next;
dualNode *p_prev;
dualNode();
};
}
namespace strs{
struct Skeleton {
struct unarList {
unarList();
tls::Size get_size();
components::unNode operator() (tls::Size set_size);
components::unNode& operator[] (tls::Index index);
void pop();
void term();
void remove();
void append(tls::Value new_value);
tls::Size get_size();
protected:
tls::Size size;
};
struct unarList:Skeleton {
components::unNode operator() (tls::Size get_size);
components::unNode& operator[] (tls::Index index);
unarList();
components::unNode *first_element;
components::unNode *last_element;
};
// struct dualList:unarList {
//
// dualList() {
// first_element = new components::dual_Node;
//
//
// }
//
//
//
// };
struct dualList {
dualList();
components::dualNode operator() (tls::Size set_size);
components::dualNode& operator[] (tls::Index index);
void pop();
void term();
void remove();
void append(tls::Value new_value);
tls::Size get_size();
protected:
tls::Size size;
components::dualNode *first_element;
components::dualNode *last_element;
};
}