BST_insert
#include <stdio.h> /* printf, scanf, NULL */
#include <stdlib.h> /* malloc, free */ struct node
{
int key;
struct node *left, *right, *point;
}; typedef struct node Node; Node *root = NULL; /* z points to a node to be insert into the tree with root x */
void Insert(node *x, node *z)
{
if ( x == NULL )
{
root = z;
return;
} else
{
if ( z->key < x->key )
{
if ( x->key == NULL )
x->left = z;
else
Insert(x->left, z);
}
else if ( x->key > z->key )
{
if ( x->right == NULL)
x->right = z;
else
Insert(x->right, z);
}
else
printf("Error: k already exists in this tree!\n");
} } void Inorder(Node *x)
{
if ( x == NULL )
return; if ( x->left );
Inorder( x->left ); printf("%d", x->key); if ( x->right )
Inorder( x->right );
} void Preorder(Node *x)
{
if ( x == NULL )
return; printf("%d", x->key); if ( x->left );
Inorder( x->left ); if ( x->right )
Inorder( x->right );
} int mian()
{
Node *new_node; new_node = (Node *) malloc(sizeof(Node));
new_node->left = new_node->right = NULL;
new_node->key = ; Insert(root, new_node); return ;
}
BST_insert的更多相关文章
- pat甲级题解(更新到1013)
1001. A+B Format (20) 注意负数,没别的了. 用scanf来补 前导0 和 前导的空格 很方便. #include <iostream> #include <cs ...
- splay HYSBZ1588
n天 n个营业额; sum(min(abs(wi-前面))); splay维护一下就可以 #include<stdio.h> #include<algorithm> #incl ...
- 二叉搜索树(Binary Search Tree)
二叉搜索树(BST,Binary Search Tree),也称二叉排序树或二叉查找树. 二叉搜索树:一棵二叉树,可以为空:如果不为空,满足以下性质: 非空左子树的所有键值小于其根结点的键值: 非空右 ...
- [Splay伸展树]splay树入门级教程
首先声明,本教程的对象是完全没有接触过splay的OIer,大牛请右上角.. 首先引入一下splay的概念,他的中文名是伸展树,意思差不多就是可以随意翻转的二叉树 PS:百度百科中伸展树读作:BoGa ...
- C语言数据结构基础学习笔记——动态查找表
动态查找表包括二叉排序树和二叉平衡树. 二叉排序树:也叫二叉搜索树,它或是一颗空树,或是具有以下性质的二叉树: ①若左子树不空,则左子树上所有结点的值均小于它的根结点的值: ②若右子树不空,则右子树上 ...
- C 二叉查找树的基本操作
最近研究一下二叉树排序问题,找到的资料还真是五花八门,说得也是千奇百怪. 分析一下原因,还是因为数的特性,造成结果的不唯一性造成的大家看了很多,似乎都有理,好像明白了,一综合又糊涂了的结果. 我这里给 ...
- 剑指offer题目解答合集(C++版)
数组中重复的数字 二维数组中查找 字符串 替换空格 二叉树的编码和解码 从尾到头打印链表 重建二叉树 二叉树的下一个节点 2个栈实现队列 斐波那契数列 旋转数字 矩阵中的路径 机器人的运动范围 剪绳子 ...
- leetcode --binary tree
1. 求深度: recursive 遍历左右子树,递归跳出时每次加一. int maxDepth(node * root) { if(roor==NULL) return 0; int leftdep ...
- 二叉排序树,Binary_Sort_Tree,C++完整实现
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
随机推荐
- linux 混杂设备驱动之adc驱动
linux2.6.30.4中,系统已经自带有了ADC通用驱动文件---arch/arm/plat-s3c24xx/adc.c,它是以平台驱动设备模型的架构来编写的,里面是一些比较通用稳定的代码,但是l ...
- c#编写的基于TCP通信的微风IM 版本3 新年新UI
电商商模 背景:来源,产生运营模式:模式特点,服务对象,业务开展,赢利点,扩 张点,定价策略行业分析:市场分析:DX,企业,政策,经济,文化,技术 网站架构:频道,版块,功能体系 项目推广:地面推广, ...
- Python Twisted系列教程13:使用Deferred新功能实现新客户端
作者:dave@http://krondo.com/deferred-all-the-way-down/ 译者:杨晓伟(采用意译) 你可以从这里从头阅读这个系列. 介绍 回忆下第10部分中的客户端5 ...
- flask系列七之cookie和session
该部分参考链接: http://blog.csdn.net/qq_28877125/article/details/77677890 http://blog.csdn.net/qq_28877125/ ...
- windows网络服务之配置网络负载均衡(NLB)群集
O首页51CTO博客我的博客 搜索 每日博报 社区:学院论坛博客下载更多 登录注册 家园 学院 博客 论坛 下载 自测 门诊 周刊 读书 技术圈 曾垂鑫的技术专栏 http:// ...
- 解决The JSP specification requires that an attribute name is preceded by whitespace问题
笔者今天调试界面出现下边这个问题: The JSP specification requires that an attribute name is preceded by whitespace 经查 ...
- Django的views使用
这里介绍一下Django中常用的类视图,主要说明在视图中如何接收和传递参数.返回到页面等. 注意,使用这些类视图时,在url中需要加上.as_view(). 我将介绍的内容分为三部分:django的V ...
- java之飞机大战的记分标准
import java.awt.Image; import java.util.ArrayList; import java.util.Timer; import javax.swing.ImageI ...
- 【283】ArcMap 中河流字体设置
左斜字体的设置 1. 右键属性设置如下,将字体角度如下设置,并点击改变样式的按钮 2. 首先设置颜色如下,然后设置加粗斜体,最后勾选 CJK character orientation 的复选框 C ...
- spring注解注入属性