📄 dt_cstr_3.cc
字号:
// file: dt_cstr_3.cc//// isip include files//#include "decision_tree.h"#include "decision_tree_constants.h"// method: constructor//// arguments:// Decision_tree& dec_tree : (input) the decision tree to copy//// return: none //// this is the copy constructor to build the tree //Decision_tree::Decision_tree(Decision_tree& dec_tree_a) { // copy the members of the tree that is passed in // if (dec_tree_a.root_d != (Dt_node*)NULL) { root_d = new Dt_node(*dec_tree_a.root_d); } else { root_d = (Dt_node*)NULL; } if(dec_tree_a.cph_d != (char_1*)NULL) { cph_d = new char_1[strlen((char*)dec_tree_a.cph_d)+1]; strcpy((char*)cph_d, (char*)dec_tree_a.cph_d); } else { cph_d = (char_1*)NULL; } state_pos_d = dec_tree_a.state_pos_d; num_leaf_d = dec_tree_a.num_leaf_d; split_threshd_d = dec_tree_a.split_threshd_d ; merge_threshd_d = dec_tree_a.merge_threshd_d ; num_occ_threshd_d = dec_tree_a.num_occ_threshd_d; // if leaf lists are not empty, copy each leaf node to the new list // if(dec_tree_a.leaf_nodes_d != (Link_list*)NULL) { Link_node* temp_head; Link_node* temp_curr; Link_node* temp_node; Dt_node* item; Dt_node* new_item; Link_node* new_head; Link_node* new_node; leaf_nodes_d = new Link_list(); temp_head = dec_tree_a.leaf_nodes_d->get_head_cc(); temp_curr = dec_tree_a.leaf_nodes_d->get_curr_cc(); temp_node = temp_head; // make a copy of the head node in old leaf list and insert it to new // leaf list // item = (Dt_node*)(temp_head->get_item_cc()); new_item = new Dt_node(*item); new_head = new Link_node((void_p)new_item); leaf_nodes_d->set_head_cc(new_head); // if there is more than one node in the old leaf list, copy each of its // Link_nodes and the Dt_node inside the Link_node // if( temp_head != temp_curr) { do { temp_node = temp_node->get_next_cc(); item = (Dt_node*)(temp_node->get_item_cc()); new_item = new Dt_node(*item); new_node = new Link_node((void_p)new_item); leaf_nodes_d->insert_cc(new_node); } while(temp_node != temp_curr); leaf_nodes_d->set_curr_cc(new_node); } else { leaf_nodes_d->set_curr_cc(new_head); } } // if old leaf list are empty, make the new leaf list a NULL pointer // else { leaf_nodes_d = (Link_list*)NULL; } // exit gracefully //}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -