Denied an approach inheritance
This commit is contained in:
parent
3cf187a4ff
commit
c6d800111c
2 changed files with 103 additions and 127 deletions
163
List.cpp
163
List.cpp
|
@ -2,111 +2,84 @@
|
||||||
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
// unNode
|
// dualNode
|
||||||
components::unNode::unNode() {
|
components::dualNode::dualNode() {
|
||||||
this->p_next = nullptr;
|
this->p_next = nullptr;
|
||||||
this->value = 0;
|
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;
|
// Structures
|
||||||
first_element = tmp;
|
|
||||||
|
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;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
//void strs::unarList::pop() {
|
||||||
|
// if (this->size == 0) return;
|
||||||
// unarList
|
// if (this->first_element->p_next != nullptr){
|
||||||
strs::unarList::unarList(){
|
// components::unNode *tmp = this->first_element->p_next;
|
||||||
this->first_element = nullptr;
|
// delete first_element;
|
||||||
this->last_element = nullptr;
|
// first_element = tmp;
|
||||||
this->size = 0;
|
// }
|
||||||
}
|
// else {
|
||||||
|
// delete first_element;
|
||||||
void strs::unarList::pop() {
|
// first_element = nullptr;
|
||||||
if (this->first_element->p_next != nullptr){
|
// }
|
||||||
components::unNode *tmp = this->first_element->p_next;
|
// --(this->size);
|
||||||
delete first_element;
|
//}
|
||||||
first_element = tmp;
|
//
|
||||||
}
|
//
|
||||||
}
|
//void strs::unarList::remove(){
|
||||||
|
// components::unNode *tmp = this->first_element;
|
||||||
void strs::unarList::remove(){
|
// while (tmp->p_next->p_next != nullptr) tmp = tmp->p_next;
|
||||||
components::unNode *tmp = this->first_element;
|
// tmp->p_next = nullptr;
|
||||||
while (tmp->p_next->p_next != nullptr) tmp = tmp->p_next;
|
// delete last_element;
|
||||||
tmp->p_next = nullptr;
|
// last_element = tmp;
|
||||||
delete last_element;
|
// --(this->size);
|
||||||
last_element = tmp;
|
//}
|
||||||
--(this->size);
|
//
|
||||||
}
|
void strs::dualList::term() {
|
||||||
|
components::dualNode *iter_node = first_element;
|
||||||
void strs::unarList::term() {
|
|
||||||
components::unNode *iter_node = first_element;
|
|
||||||
for (tls::Index i = 0; i < size; i++){
|
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;
|
iter_node = iter_node->p_next;
|
||||||
}
|
}
|
||||||
std::cout << "-------------------------------------------------------------" << std::endl;
|
std::cout << "-------------------------------------------------------------" << std::endl;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
void strs::unarList::append(tls::Value new_value) {
|
//void strs::unarList::append(tls::Value new_value) {
|
||||||
this->last_element->p_next = new components::unNode;
|
// this->last_element->p_next = new components::unNode;
|
||||||
this->last_element = this->last_element->p_next;
|
// this->last_element = this->last_element->p_next;
|
||||||
this->last_element->value = new_value;
|
// this->last_element->value = new_value;
|
||||||
++(this->size);
|
// ++(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
67
List.hpp
67
List.hpp
|
@ -3,64 +3,67 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "tools.hpp"
|
#include "tools.hpp"
|
||||||
#include <strstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace components{
|
namespace components{
|
||||||
|
|
||||||
struct unNode{
|
struct unNode{
|
||||||
unNode *p_next;;
|
unNode *p_next;
|
||||||
tls::Value value;
|
tls::Value value;
|
||||||
|
|
||||||
unNode();
|
unNode();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dualNode:unNode {
|
struct dualNode {
|
||||||
tls::Value *p_prev;;
|
tls::Value value;
|
||||||
|
dualNode *p_next;
|
||||||
|
dualNode *p_prev;
|
||||||
|
dualNode();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace strs{
|
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 pop();
|
||||||
void term();
|
void term();
|
||||||
void remove();
|
void remove();
|
||||||
void append(tls::Value new_value);
|
void append(tls::Value new_value);
|
||||||
|
|
||||||
|
tls::Size get_size();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
tls::Size size;
|
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 *first_element;
|
||||||
components::unNode *last_element;
|
components::unNode *last_element;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// struct dualList:unarList {
|
|
||||||
//
|
struct dualList {
|
||||||
// dualList() {
|
dualList();
|
||||||
// first_element = new components::dual_Node;
|
|
||||||
//
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue