Skip to content
Snippets Groups Projects
Commit 85beebca authored by Giann Karlo Aguirre Samboní's avatar Giann Karlo Aguirre Samboní
Browse files

Get_info method in Nodes implemented

parent be817d99
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,9 @@ int main(){
std::cout << *it << ' ';
} */
std::cout << endl;
cout << node_six->get_parents() << endl;
cout << node_six->get_children() << endl;
cout << node_six->get_info() << endl;
/*tree->preorder_print();
tree->inorder_print();
tree->postorder_print();
......
......@@ -116,5 +116,41 @@ void TreeNode::set_next_sibling (TreeNode *next_sibling){
this->next_sibling_ = next_sibling;
}
/* Other methods */
string TreeNode::get_parents(){
string parents = "";
TreeNode* tmp_node = new TreeNode();
tmp_node = this->first_parent_;
while(tmp_node != nullptr){
tmp_node->next_pibling_ == nullptr ? parents += to_string(tmp_node->id) : parents += to_string(tmp_node->id) + ", ";
tmp_node = tmp_node->next_pibling_;
}
return parents;
}
string TreeNode::get_children(){
string children = "";
TreeNode* tmp_node = new TreeNode();
tmp_node = this->first_child_;
while(tmp_node != nullptr){
tmp_node->next_sibling_ == nullptr ? children += to_string(tmp_node->id) : children += to_string(tmp_node->id) + ", ";
tmp_node = tmp_node->next_sibling_;
}
return children;
}
string TreeNode::get_info (){
string info_node = "Node";
info_node += "(id = " + to_string(this->id) + "; ";
info_node += "Node type = " + to_string(this->node_type_) + "; ";
info_node += "Goal = " + this->goal_ + "; ";
info_node += "Value = " + to_string(this->value_) + "; ";
info_node += "Parents = " + this->get_children() + "; ";
info_node += "Children = " + this->get_parents() + ")";
return info_node;
}
int TreeNode::current_id = 0;
......@@ -71,17 +71,9 @@ class TreeNode{
/* Others methods*/
//Adding...
void add_child(TreeNode *new_child, TreeNode *parent);
void add_parent(TreeNode *new_parent, TreeNode *child);
void add_child_pos(TreeNode *new_child, TreeNode *parent, int pos);
void add_parent_pos(TreeNode *new_parent, TreeNode *child, int pos);
//Removing...
void remove_child(TreeNode *cur_child, TreeNode *parent);
void remove_parent(TreeNode *cur_parent, TreeNode *child);
void remove_child_pos(int pos, TreeNode *parent);
void remove_parent_pos(int pos, TreeNode *child);
string get_info ();
string get_parents();
string get_children();
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment