- 浏览: 1452157 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
参考的这个视频
视频讲得有点烂,代码错误很多,诶,不过ptree似乎挺好,挺直观的
递归都能变成栈? 中序遍历,先序遍历,后续遍历都是栈,层序遍历用的队列
bst数的,增删
---------------------------------
红黑树:
视频中的ptree应该是自己写的一个层序遍历的例子
层序遍历大概这样,还需要完善下:
http://www.cppblog.com/ngaut/archive/2012/09/06/2351.html
打印树
:
编译的时候需要 gcc -lm -lcurses ctree.c
需要安装ncurses
参考了
http://biancheng.dnbcw.info/linux/248916.html
视频讲得有点烂,代码错误很多,诶,不过ptree似乎挺好,挺直观的
递归都能变成栈? 中序遍历,先序遍历,后续遍历都是栈,层序遍历用的队列
bst数的,增删
[root@VM_253_237_tlinux ~/tree]# cat bst.c #include <stdlib.h> #include <stdio.h> #include <time.h> #define N 10 typedef struct node *link; struct node{ int item;link l,r; }; link NODE(int item,link l,link r){ link t=malloc(sizeof *t); t->item=item;t->l=l;t->r=r; return t; } link insert_node(link t,int item){ if(t==NULL) return NODE(item,NULL,NULL); if(item<t->item) t->l=insert_node(t->l,item); else t->r=insert_node(t->r,item); return t; } void pprint(link t){ printf("("); if(t!=NULL){ printf("%d",t->item); pprint(t->l); pprint(t->r); } printf(")"); } int bst_search(link t,int item){ if(t==NULL) return 0; if(item<t->item)return bst_search(t->l,item); else if(item>t->item) return bst_search(t->r,item); else return 1; } link bst_remove(link t,int item){ if(t==NULL) return NULL; if(item<t->item) t->l=bst_remove(t->l,item); else if(item>t->item){ t->r=bst_remove(t->r,item); }else { link x; if(t->l){ for(x=t->l;x->r;x=x->r){;} t->item=x->item; t->l=bst_remove(t->l,t->item); }else if(t->r){ for(x=t->r;x->l;x=x->l){;} t->item=x->item; t->r=bst_remove(t->l,t->item); }else{ free(t);t=NULL; } } return t; } int main(){ srand(time(NULL)); int i ;link root=NULL; for(i=0;i<N;i++) root =insert_node(root,rand()%100); printf("\t\\tree");pprint(root); printf("\n"); printf("%d\n",bst_search(root,50)); root=bst_remove(root,root->item); printf("\t\\tree");pprint(root); return 0; }
---------------------------------
红黑树:
#include <stdlib.h> #include <stdio.h> #include <time.h> #define N 10 typedef struct node *link; struct node{ int item,red;link l,r; }; link null; link NODE(int item,link l,link r,int red){ link t=malloc(sizeof *t); t->item=item;t->l=l;t->r=r;t->red=red; return t; } link rotR(link t){ link x=t->l;t->l=x->r;x->r=t;return x; } link rotL(link t){ link x=t->r;t->r=x->l;x->l=t;return x; } void pprint(link t){ printf("("); if(t!=null){ printf("%d%c",t->item,t->red?'+':' '); pprint(t->l); pprint(t->r); } printf(")"); } link RBinit(){ null=NODE(0,NULL,NULL,0); null->l=null;null->r=null; return null; } link insert_node(link t ,int item, int sw){ if(t==null) return NODE(item,null,null,1); if(t->l->red && t->r->red){ t->red=1;t->l->red=0;t->r->red=0; } if(item<t->item){ t->l=insert_node(t->l,item,0); if(t->red && t->l->red && sw) t=rotR(t); if(t->l->red && t->l->l->red) { t=rotR(t); t->red=0; t->r->red=1; } }else{ t->r=insert_node(t->r,item,1); if(t->red && t->r->red && !sw) t=rotL(t); if(t->r->red && t->r->r->red) { t=rotL(t); t->red=0; t->l->red=1; } } return t; } link RBinsert(link root,int item){ root=insert_node(root,item,0); root->red=0; return root; } int main(){ int i=0; srand(time(NULL)); link root=RBinit(); for(i=0;i<N;i++) root=RBinsert(root,rand()%100); printf("\t\\tree"); pprint(root); printf("\n"); return 0; }
视频中的ptree应该是自己写的一个层序遍历的例子
层序遍历大概这样,还需要完善下:
[root@VM_253_237_tlinux ~/tree]# cat ltree.c #include <stdlib.h> #include <stdio.h> #define max(a,b) (a>b?a:b) typedef struct Node *link; struct Node{ int item;link l,r; }; link NODE(int item,link l,link r){ link t=malloc(sizeof *t); t->item=item;t->l=l;t->r=r; return t; } link Construct() { link node4 = NODE(7, NULL, NODE(3,NULL,NULL)); link node3 = NODE(4,NULL,NULL); link node2 = NODE(12,NULL,NULL); link node1 = NODE(5, node3, node4); link root = NODE(10, node1, node2); return root; } int PrintByLevel(link root, int level) { if(root == NULL) return 0; if(level == 1) { printf("%d ",root->item); return 1; } return PrintByLevel(root->l, level - 1) + PrintByLevel(root->r, level - 1); } int GetTreeHeight(link root) { if(root == NULL) return 0; return max(GetTreeHeight(root->l) + 1, GetTreeHeight(root->r) + 1); } int main() { link root = Construct(); int height = GetTreeHeight(root); int i=0; for( i = 1; i <= height; i++) { PrintByLevel(root, i); printf("\n"); } return 0; }
http://www.cppblog.com/ngaut/archive/2012/09/06/2351.html
打印树
:
#include <stdlib.h> #include <stdio.h> #include <math.h> #include <curses.h> #include <time.h> #define N 10 typedef struct node *link; struct node{ int item;link l,r; }; static void recur_print( struct node * node, int line, int col ){ if( node == NULL ){ move( line, col ) ; addstr("*");//此处为加*号的代码,用来占位,可去掉。 return ; } int t = COLS/pow( 2, line+2 ); char buf[9]; sprintf(buf,"%-d", node->item ) ; move( line , col ) ; addstr( buf ) ; if( node->l != NULL || node->r != NULL ){ move(line+1, col-t-1 ) ; addstr("["); move(line+1, col+t+3) ; addstr("]"); } recur_print( node->l, line+1, col-t ) ; recur_print( node->r, line+1, col+t ) ; } void print_tree(struct node * root){ initscr() ; clear(); recur_print(root, 0, COLS/2); move(LINES-1, COLS-1) ; refresh() ; getchar() ; endwin() ; } link NODE(int item,link l,link r){ link t=malloc(sizeof *t); t->item=item;t->l=l;t->r=r; return t; } link insert_node(link t,int item){ if(t==NULL) return NODE(item,NULL,NULL); if(item<t->item) t->l=insert_node(t->l,item); else t->r=insert_node(t->r,item); return t; } void pprint(link t){ printf("("); if(t!=NULL){ printf("%d",t->item); pprint(t->l); pprint(t->r); } printf(")"); } int bst_search(link t,int item){ if(t==NULL) return 0; if(item<t->item)return bst_search(t->l,item); else if(item>t->item) return bst_search(t->r,item); else return 1; } int main(){ printf("aaa"); srand(time(NULL)); int i ;link root=NULL; for(i=0;i<N;i++) root =insert_node(root,rand()%100); printf("\n"); printf("\t\\tree");pprint(root); print_tree(root); return 0; }
编译的时候需要 gcc -lm -lcurses ctree.c
需要安装ncurses
参考了
http://biancheng.dnbcw.info/linux/248916.html
发表评论
-
xl2tp 备份
2019-09-24 16:25 5872019年9月24日更新: 注意,需要开启firewall ... -
sdl笔记
2019-01-31 17:19 698sdl教程教程 https://github.com/Twin ... -
tinyemu
2019-01-24 17:59 1412参考https://bellard.org/jslinux/t ... -
aws搭建xl2tp给iphone使用
2018-12-26 21:37 18292019年12月26日 可以参考原来的配置 https:// ... -
consul的基本使用
2017-06-27 11:13 1364### 安装 [centos7上consul的安装](ht ... -
lvs的helloworld
2017-06-13 20:36 570###################lvs######### ... -
系统调用的helloworld
2017-05-04 16:14 568《2.6内核标准教程》 p293 #include < ... -
bitcoin和cgminer的安装
2017-04-05 22:45 1930参考 http://blog.csdn.net/rion_ch ... -
ceph安装和常用命令
2017-03-21 21:55 921/etc/hosts ssh-keygen ssh-copy- ... -
mobile terminal 笔记
2016-12-02 15:35 554找出旧的iphone4 越狱之后可以变个小操作系统 mobi ... -
socket基础和select(python)
2016-06-14 17:21 1772上接 c语言的socket基础ht ... -
socket基础(c语言)
2016-06-14 16:45 959不使用select 普通的基础socket连接,对多个客户端的 ... -
ffmpeg+nginx 的直播(2,直播摄像头和麦克风)
2016-05-28 20:21 4272假设我的服务器是centos7 192.168.139.117 ... -
ffmpeg+nginx 的直播(1,直播播放的视频文件)
2016-05-26 17:11 653464位操作系统centos7 ############ 1.一 ... -
socat和netcat(nc)
2016-04-29 22:36 1695转 原文链接: http://www.wenquan.name ... -
neutron基础九(qemu nat网络)
2016-02-06 17:21 1571接上基础八,kvm透传nested忽略 1.在主机ce ... -
neutron基础八(qemu 桥接网络)
2016-02-06 13:13 1505qemu的桥接和nat的qemu启动命令是一样的,但是后续的脚 ... -
neutron基础七(qemu tap)
2016-02-02 17:02 981使用qemu 建立个虚拟机 然后用tap设备, 根据基础六,t ... -
neutron基础六(bridge fdb)
2016-01-28 18:30 2160转发表 在三台机器上建立三个namespace 192.16 ... -
南北流量
2016-01-23 23:26 1776一、三层网络架构: 接入层:负责服务器的接入和隔离 汇聚层:汇 ...
相关推荐
平衡二叉树-红黑树的实现
数据结构 树、二叉树、红黑树、堆、图等结构教程
数据结构 和算法分析 二叉树、红黑树、堆、图等数据结构
该生成器可以根据用户的要求生成任何用户所需要的类型的二叉树
高级数据结构代码 红黑树 二叉树 B树
描述了红黑树的基本结构 以及与二叉树的性能比较
talerbtree红黑树二叉树.zip
2,为什么索引结构默认使用B+Tree,而不是Hash,二叉树,红黑树? 3、MySQL里记录货币用什么字段类型好 4、数据库自增主键可能遇到什么问题。 5、从锁的类别角度讲,MySQL都有哪些锁呢? 6、索引失效情况? 7、优化...
红黑树的本质是二叉树,二叉树在插入元素的时候是根据关键字(可以理解为用来识别每个节点的id,一般是hash 来判断)的大小来判断插入到哪一个分支的,如下图所示: (备注:大写字母代表每个节点相当于每个节点的...
红黑树&二叉树
B树和二叉树的区别:二叉树最多能有两个子节点;B树最多只能有M个子节点,最少有三个子节点 三、B+树 介绍:B+树是B树的升级版本,就目前情况,绝大部分都已经用B+树代替了B树了,文件管理、索引等等 四、红黑树 ...
红黑树是一种特化的AVL树(平衡二叉树),都是在进行插入和删除操作时通过特定操作保持二叉查找树的平衡,从而获得较高的查找性能。 它虽然是复杂的,但它的最坏情况运行时间也是非常良好的,并且在实践中是高效的:...
主要实现有普通树的生成、查询方法,与继承于普通树的二叉树、红黑树的实现。
第一,散列表中的数据是无序存储的,如果要输出有序的数据,需要先进行排序 第二,散列表扩容耗时很多,而且当遇到散列冲突时,性能不稳定,尽管二叉查找树的性能不稳定,
1按先序次序输入二叉树中结点的值(一个字符),`0`表示空树,生成二叉树的二叉链表存储结构。然后按中序和后序顺序遍历二叉树输出结果。
二叉树 非递归实现 数据结构 c++ 广度遍历,非递归实现广度遍历生成二叉树。 数据结构与算法上机作业。
这是一个关于二叉树的代码,演示了红黑树的数据结构。仅供大家学习和参考!
用先序生成二叉树,然后按先序,中序,后序和层次对二叉树进行排序
使用java语言编程实现了平衡二叉树、二叉树、二叉搜索树、红黑树四种树相关的数据结构,还实现了多种排序算法。并且是在J2EE下实现的。
26红黑树 27红黑树_0 28红黑树_1 29红黑树_2 30红黑树_3 31红黑树_4 32红黑树_5 33红黑树_6 34堆 35堆排序 36哈希与映射的概述 37B树有什么用 38B树的概念 39图_邻接矩阵 40图_邻接表 41图_DFS 42图_BFS