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++;
}
{
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
- Binary_tree插入
- [数据结构]Binary_tree | Binary_search_tree | avl_tree
- BST(binary search tree)类型题目需要用到的头文件binary_tree.h
- 插入、
- 插入
- 插入
- 插入排序--直接插入
- 插入排序--折半插入
- 插入排序:表插入
- 插入排序-【插入排序】
- 插入排序------直接插入
- 插入排序---直接插入
- 插入排序--折半插入
- android 通话记录插入 短信插入 联系人插入
- 插入排序(简单插入&折半插入)
- 插入算法(直接插入,二分插入,希尔)
- Mysql 插入 存在不插入,不存在插入
- 批量插入
- Android SwitchButton(滑动开关)
- sublime text3 安装插件
- srvctl命令详解
- 初踏ACM之路
- 【整理】c++中的操作符们
- Binary_tree插入
- POJ 2499 Binary Tree
- FZU problem 1896 单调队列
- Hadoop中Mapper类的setup()函数在什么地方调用
- ret hat linux 全屏
- 用OpenSceneGraph实现的NeHe OpenGL教程 - 第三十八课
- hibernate 双向n-n
- Java反射学习总结五(Annotation(注解)-基础篇)
- VIM的编码相关,encoding, filecoding, termencoding