Binary_tree插入

来源:互联网 发布:unity3d 刚体移动 编辑:程序博客网 时间:2024/06/17 19:15
void Tree<Entry>::insert(Entry &x)
{
if(empty())
{
root=new Binary_node<Entry>(x);
count++;
return;
}
stack<int> s;
int tempcount=size();
while(tempcount>0)
{
if(tempcount%2==0)
s.push(2);
else
s.push(1);
tempcount=(tempcount-1)/2; 
};
Binary_node<Entry> *current=root;
int a;
while(s.size()>1)
{


a=s.top();
s.pop();
if(a==1)
current=current->left;
else
current=current->right;
}
a=s.top();
if(a==1)
current->left=new Binary_node<Entry>(x);
else
current->right=new Binary_node<Entry>(x);
count++;


}
0 0
原创粉丝点击