本文整理汇总了C++中BinaryTree::access_height方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::access_height方法的具体用法?C++ BinaryTree::access_height怎么用?C++ BinaryTree::access_height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree::access_height方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildTreeNodeBitlabel
void BuildTreeNodeBitlabel(BinaryTree& btree, int& current_node, vector<MACHINE_WORD>& TreeNodeBitLabel){
if (btree[current_node].left_child>=0){
TreeNodeBitLabel[btree[current_node].left_child]=TreeNodeBitLabel[current_node];
BitOperators::set_zero(TreeNodeBitLabel[btree[current_node].left_child], btree.access_height()-btree[btree[current_node].left_child].level+1);
BitOperators::set_one(TreeNodeBitLabel[btree[current_node].left_child], btree.access_height()-btree[btree[current_node].left_child].level);
BuildTreeNodeBitlabel(btree, btree[current_node].left_child, TreeNodeBitLabel);
}
if(btree[current_node].right_child>=0){
TreeNodeBitLabel[btree[current_node].right_child]=TreeNodeBitLabel[current_node];
BitOperators::set_one(TreeNodeBitLabel[btree[current_node].right_child], btree.access_height()-btree[btree[current_node].right_child].level);
BuildTreeNodeBitlabel(btree, btree[current_node].right_child, TreeNodeBitLabel);
}
}
示例2: buildBinaryTree
//.........这里部分代码省略.........
cout<<"Internal logic error 2 (multiple parents) ocurrs on binary tree construction."<<endl;
}
}
}
if (parent==-1){//implies root node
subsize_root.insert(pair<int, int>(total_size+1, current_node));
}
btree[current_node].parent=parent;
if(subsize_node.size()==1){
btree[current_node].left_child=(subsize_node.begin())->second;
}else if (subsize_node.size()==2){
multimap<int, int>::iterator mit=subsize_node.begin();
btree[current_node].left_child=mit->second;
mit++;
btree[current_node].right_child=mit->second;
}else if (subsize_node.size()>2){
while(subsize_node.size()>2){
int first_size=(subsize_node.begin())->first;
int first_node=(subsize_node.begin())->second;
subsize_node.erase(subsize_node.begin());
int second_size=(subsize_node.begin())->first;
int second_node=(subsize_node.begin())->second;
subsize_node.erase(subsize_node.begin());
int new_node_id=btree.num_nodes();
//add a virtual node
btree.addNode(new_node_id);
virtualnode_to_realnode.push_back(current_node);
//add a virtual node done
btree[new_node_id].left_child=first_node;
btree[new_node_id].right_child=second_node;
btree[first_node].parent=new_node_id;
btree[second_node].parent=new_node_id;
subsize_node.insert(pair<int, int>(first_size+second_size, new_node_id));
}
multimap<int, int>::iterator mit=subsize_node.begin();
btree[current_node].left_child=mit->second;
btree[mit->second].parent=current_node;
mit++;
btree[current_node].right_child=mit->second;
btree[mit->second].parent=current_node;
}
}
int root=-1;
if(subsize_root.size()==1){
root=(subsize_root.begin())->second;
}else if (subsize_root.size()>1){
while(subsize_root.size()>1){
int first_size=(subsize_root.begin())->first;
int first_node=(subsize_root.begin())->second;
subsize_root.erase(subsize_root.begin());
int second_size=(subsize_root.begin())->first;
int second_node=(subsize_root.begin())->second;
subsize_root.erase(subsize_root.begin());
int new_node_id=btree.num_nodes();
//add a virtual node
btree.addNode(new_node_id);
virtualnode_to_realnode.push_back(-1);//If the root node is a virtual node, there is no real node can be associated with it.
//add a virtual node done
btree[new_node_id].left_child=first_node;
btree[new_node_id].right_child=second_node;
btree[first_node].parent=new_node_id;
btree[second_node].parent=new_node_id;
subsize_root.insert(pair<int, int>(first_size+second_size, new_node_id));
root=new_node_id;
}
}
if(root<0){
cout<<"The btree is empty. Please check input."<<endl;
return;
}else{
btree.access_root()=root;
btree[root].level=0;
int maximum_level=0;
queue<int> q;
q.push(root);
while(q.size()>0){
int j=q.front();
q.pop();
maximum_level=maximum_level>btree[j].level?maximum_level:btree[j].level;
if (btree[j].left_child>=0){
btree[btree[j].left_child].level=btree[j].level+1;
q.push(btree[j].left_child);
}
if (btree[j].right_child>=0){
btree[btree[j].right_child].level=btree[j].level+1;
q.push(btree[j].right_child);
}
}
btree.access_height()=maximum_level;
}
}