#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits>
#include<vector>
using namespace std;
struct BST{
int key;
BST *lc, *rc;
BST(){
this->key = ;
lc = rc = NULL;
}
BST(int k){
this->key = k;
lc = rc = NULL;
}
};
BST* newNode(int item){
BST *tmp = (BST*)malloc(sizeof(BST));
tmp->key = item;
tmp->lc = tmp->rc = NULL;
return tmp;
}
BST* insert(BST *root, int item){
if(root==NULL) return newNode(item);
if(item < root->key){
root->lc = insert(root->lc,item);
}
else if(item > root->key){
root->rc = insert(root->rc,item);
}
return root;
}
void inorder(BST *root){
if(root!=NULL){
inorder(root->lc);
cout<< root->key << endl;
inorder(root->rc);
}
}
int main(){
BST *root = new BST();
for(int i=;i<=;i+=){
root = insert(root, i);
}
inorder(root);
return ;
}

dataStructure@ Binary Search Tree的更多相关文章

  1. 【数据结构05】红-黑树基础----二叉搜索树(Binary Search Tree)

    目录 1.二分法引言 2.二叉搜索树定义 3.二叉搜索树的CRUD 4.二叉搜索树的两种极端情况 5.二叉搜索树总结 前言 在[算法04]树与二叉树中,已经介绍过了关于树的一些基本概念以及二叉树的前中 ...

  2. [数据结构]——二叉树(Binary Tree)、二叉搜索树(Binary Search Tree)及其衍生算法

    二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现 ...

  3. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  4. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  5. Leetcode: Convert sorted list to binary search tree (No. 109)

    Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...

  6. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  7. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

  8. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  9. [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

随机推荐

  1. 一个比较全面的DJANGO_REST_FRAMEWORK的CASE

    验证啊,过滤啊,hypermedia as the engine of ap‐plication state (HATEOAS)啊都有的. urls.py __author__ = 'sahara' ...

  2. 【原创】oracle的tpc-c测试及方法

    大家好,很高兴来到博客园分享自己的所见所得.希望和大家多多交流,共同进步. 本文重点在于简介使用BenchmarkSQL对oracle进行tpcc的测试步骤,只是一个简单入门的过程. 开源测试工具:B ...

  3. RTDX target application does not match emulation protocol!

    2013-06-20 10:19:22 在CCS2.0 的emulator写dsp/bios 的程序,编译链接无错误,而点击LOAD Program下载xxx.out完成时弹出如下对话框: RTDX ...

  4. memcpy与memmove区别

    头文件:#include <string.h> memmove() 用来复制内存内容,其原型为:    void * memmove(void *dest, const void *src ...

  5. sharedevelop iis express

    sharedevelop 的IIS express的配置文件在 %userprofile%\documents\IISExpress\config\applicationhost.config 自动会 ...

  6. bzoj1858: [Scoi2010]序列操作

    lazy-tag线段树. #include<cstdio> #include<algorithm> #include<cstring> using namespac ...

  7. [转] struts.xml配置详解

    转自:http://www.cnblogs.com/fmricky/archive/2010/05/20/1740479.html struts.xml是我们在开发中利用率最高的文件,也是Struts ...

  8. sql 的错误处理功能很弱

    --下面演示了SQL错误处理的脆弱性--邹建 --演示1--测试的存储过程1create proc p1asprint 12/0if @@error<>0print '发生错误1' sel ...

  9. I.MX6 bq27441 driver hacking

    /************************************************************************* * I.MX6 bq27441 driver ha ...

  10. Idea无法DEBUG的问题

    最近对web工程进行debug,突然发现无法进入断点了,原来以为是maven的问题,后来发现是tomcat环境变量导致的. 使用tomcat时经常碰到内存不足的情况,我们会对catalina.bat类 ...