#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的更多相关文章

  1. pat甲级题解(更新到1013)

    1001. A+B Format (20) 注意负数,没别的了. 用scanf来补 前导0 和 前导的空格 很方便. #include <iostream> #include <cs ...

  2. splay HYSBZ1588

    n天 n个营业额; sum(min(abs(wi-前面))); splay维护一下就可以 #include<stdio.h> #include<algorithm> #incl ...

  3. 二叉搜索树(Binary Search Tree)

    二叉搜索树(BST,Binary Search Tree),也称二叉排序树或二叉查找树. 二叉搜索树:一棵二叉树,可以为空:如果不为空,满足以下性质: 非空左子树的所有键值小于其根结点的键值: 非空右 ...

  4. [Splay伸展树]splay树入门级教程

    首先声明,本教程的对象是完全没有接触过splay的OIer,大牛请右上角.. 首先引入一下splay的概念,他的中文名是伸展树,意思差不多就是可以随意翻转的二叉树 PS:百度百科中伸展树读作:BoGa ...

  5. C语言数据结构基础学习笔记——动态查找表

    动态查找表包括二叉排序树和二叉平衡树. 二叉排序树:也叫二叉搜索树,它或是一颗空树,或是具有以下性质的二叉树: ①若左子树不空,则左子树上所有结点的值均小于它的根结点的值: ②若右子树不空,则右子树上 ...

  6. C 二叉查找树的基本操作

    最近研究一下二叉树排序问题,找到的资料还真是五花八门,说得也是千奇百怪. 分析一下原因,还是因为数的特性,造成结果的不唯一性造成的大家看了很多,似乎都有理,好像明白了,一综合又糊涂了的结果. 我这里给 ...

  7. 剑指offer题目解答合集(C++版)

    数组中重复的数字 二维数组中查找 字符串 替换空格 二叉树的编码和解码 从尾到头打印链表 重建二叉树 二叉树的下一个节点 2个栈实现队列 斐波那契数列 旋转数字 矩阵中的路径 机器人的运动范围 剪绳子 ...

  8. leetcode --binary tree

    1. 求深度: recursive 遍历左右子树,递归跳出时每次加一. int maxDepth(node * root) { if(roor==NULL) return 0; int leftdep ...

  9. 二叉排序树,Binary_Sort_Tree,C++完整实现

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

随机推荐

  1. Linux性能监测:监测目的与工具介绍

    性能监测是系统优化过程中重要的一环,如果没有监测.不清楚性能瓶颈在哪里,优化什么呢.怎么优化呢?所以找到性能瓶颈是性能监测的目的,也是系统优化的关键.本文对Linux性能监测的应用类型.底线和监测工具 ...

  2. ubuntu双网卡准备配置

    近日有个需求,交换机有两台,做了堆叠,服务器双网卡,每个分别连到一台交换机上.这样就需要将服务器的网卡做成主备模式,以增加安全性,使得当其中一个交换机不通的时候网卡能够自动切换. 整体配置不难,网上也 ...

  3. krpano之字幕添加

    字幕是指介绍语音的字幕,字幕随着语音的播放而滚动,随语音暂停而暂停.字幕添加的前提是用之前的方法添加过介绍语音. 原理: 字幕层在溢出隐藏的父元素中向右滑动,当点击声音控制按钮时,字幕位置被固定,再次 ...

  4. leetcode427

    本题不会做,从网上找到了python3的解法,记录如下. class Solution: def construct(self, grid): def dfs(x, y, l): if l == 1: ...

  5. 微信公众平台PHP示例一

    <?php /** * Created by PhpStorm. * User: Administrator * Date: 2015-12-18 * Time: 21:51 */ define ...

  6. scala 在vim中的语法高亮

    https://github.com/derekwyatt/vim-scala 提供了一个选择 看install手册,发现两个命令都是必须的. mkdir -p ~/.vim/{ftdetect,in ...

  7. 如何在Less中使用使用calc

    文章转载自  琼台博客:http://www.qttc.net/201409448.html Less的好处不用说大家都知道,确实让写CSS的人不在痛苦了,最近我在Less里加入calc时确发现了有点 ...

  8. python asyncio 异步实现mongodb数据转xls文件

    from pymongo import MongoClient import asyncio import xlwt import json class Mongodb_Transfer_Excel( ...

  9. Professional C# 6 and .NET Core 1.0 - Chapter 38 Entity Framework Core

    本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - Chapter 38 Entity F ...

  10. 171. Excel Sheet Column Number Excel表格的字母转成数字

    [抄题]: Given a column title as appear in an Excel sheet, return its corresponding column number. For ...