二叉排序树
来源:互联网 发布:软件授权码绑定 编辑:程序博客网 时间:2024/04/30 21:03
如果你了解二叉树的特性,和二叉排序树的排序原理的话就比较好写了,不懂的话可以 看看资料~~
#include <iostream>#include <cstring>using namespace std;struct tree{ int date; struct tree *left; struct tree *right;};void init (tree *&t){ t=(tree*)malloc(sizeof(tree)); t->left=NULL; t->right=NULL;}void Create_BST(tree *&t,int key){ if(t==NULL){ tree *s;init(s);s->date=key;t=s; return ; } if(key>=t->date) Create_BST(t->right,key); if(key<t->date) Create_BST(t->left,key); return ;}void BST_LDR(tree *&t) { if(t==NULL) return ; BST_LDR(t->left); cout<<t->date<<" "; BST_LDR(t->right);}int main(){ int n; while(cin>>n) { int s; tree *t; for(int i=1;i<=n;i++) { cin>>s; if(i==1){ init(t); t->date=s; continue; } Create_BST(t,s); } BST_LDR(t); }return 0;}
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- 二叉排序树
- spring mvc的基本配置
- windows 下配置JDK环境变量
- 宏定义(备用)
- 杭电2000
- C++数据结构与STL--栈的实现
- 二叉排序树
- ASP.NET大数据量分页技术的初步体验技巧
- 制作系统光盘安装时提示Media test failure,check cable
- 如何用批处理命令批量配对重命名
- 50个经典的SQL语句
- 工作一周记
- 工作慢慢累计
- git 查看远程分支、本地分支、创建分支、把分支推到远程repository、删除本地分支
- HDU 1253 胜利大逃亡(BFS)