- 浏览: 36124 次
文章分类
- 全部博客 (41)
- 卧鸟个去 (2)
- Transform (2)
- Mathmatic (9)
- Plant-Tree (7)
- Data-Struct (12)
- Red-Black-Tree (1)
- Radix-Tree (1)
- Trie (2)
- String (4)
- BST (2)
- Amazing-Union-Find-Set (1)
- HDU (27)
- OJ (32)
- BFS (3)
- Pretty-Suffix-Array (2)
- POJ (6)
- Graceful-Segment-Tree (2)
- Geometry (6)
- Priority-Queue (2)
- Dynamic-Programing (1)
- DP (3)
- LCS (1)
- Convex-Hull (2)
- Triangulation (1)
- DFS (3)
- Combinatorial-Mathematics (2)
- Big-Number (1)
- Statistic (3)
- STL (1)
- Shortest-Path (3)
- ZOJ (1)
- Leftist-Tree (1)
- Prime (1)
- Binary-Index-Tree (1)
- (1)
- Stack (1)
- SPFA (0)
- CRT (1)
今日系我大一下学期第二日……
之前睇左好多结构都未实践,今日无咩做,用五个钟左右种左一颗多功能二叉树,支持如下操作:
1.build(s,n){有随机开关,随便开{……^____^}}--------以一堆数为基础建树。
2.insert(key)--------插入结点。
3.del(key)--------删除指定关键字所在第一个结点。
4.cut(key)--------剪支(砍左以关键字key为根ge第一课子树)。
5.search(key)--------返回指定关键字第一个(因为有可能重复)指针。
6.max()--------返回整棵树ge最大关键字。
7.min()--------返回整棵树ge最小关键字。
8.pre(key)--------返回指定关键字ge前驱。
9.suc(key)--------返回指定关键字ge后继。
10.front_print()--------输出前序遍历。
11.middle_print()---------输出中序遍历。
12.behind_print()---------输出后序遍历。
13.left_son(key)--------返回关键字第一个结点ge左细路。
14.right_son(key)--------返回关键字第一个结点ge右细路。
15.l_rotate(key)--------左旋转第一个以key为关键字ge结点。
16.l_rotate(key)--------右旋转第一个以key为关键字ge结点。
17.get_root()---------返回根结点指针。
18.empty()--------检查树系唔系空左。
总共18个功能,各有用处挂我觉得,善用尼18个功能都几好ge~~5个钟其实大部分时间都系系度搵bug,有d感受到程序员个d痛苦。尼棵树剩系int容器,当然可以修改成为任意容器啦~~~{=___=}。
好咯……吾讲甘多废话拉,睇下代码咯。
可以复制落电脑度玩下d左旋右旋ge~~~有bug提醒我窝{OTZ}
最后为杭电OJ ge速度感到悲哀……
之前睇左好多结构都未实践,今日无咩做,用五个钟左右种左一颗多功能二叉树,支持如下操作:
1.build(s,n){有随机开关,随便开{……^____^}}--------以一堆数为基础建树。
2.insert(key)--------插入结点。
3.del(key)--------删除指定关键字所在第一个结点。
4.cut(key)--------剪支(砍左以关键字key为根ge第一课子树)。
5.search(key)--------返回指定关键字第一个(因为有可能重复)指针。
6.max()--------返回整棵树ge最大关键字。
7.min()--------返回整棵树ge最小关键字。
8.pre(key)--------返回指定关键字ge前驱。
9.suc(key)--------返回指定关键字ge后继。
10.front_print()--------输出前序遍历。
11.middle_print()---------输出中序遍历。
12.behind_print()---------输出后序遍历。
13.left_son(key)--------返回关键字第一个结点ge左细路。
14.right_son(key)--------返回关键字第一个结点ge右细路。
15.l_rotate(key)--------左旋转第一个以key为关键字ge结点。
16.l_rotate(key)--------右旋转第一个以key为关键字ge结点。
17.get_root()---------返回根结点指针。
18.empty()--------检查树系唔系空左。
总共18个功能,各有用处挂我觉得,善用尼18个功能都几好ge~~5个钟其实大部分时间都系系度搵bug,有d感受到程序员个d痛苦。尼棵树剩系int容器,当然可以修改成为任意容器啦~~~{=___=}。
好咯……吾讲甘多废话拉,睇下代码咯。
//Muti-Function-Binary-Search-Tree //Athtor SGetEternal{=___+}凸 class BST { private: struct node { node *p,*left,*right; int key; }; node *root,*x,*y,*w; void make_node(node *&temp) { temp=new node; temp->p=NULL; temp->left=NULL; temp->right=NULL; temp->key=0; } public: node* search(int key) { if (empty()) { printf("The tree is empty!!/n"); return NULL; } x=root; while (x->key!=key) { if (key>x->key) x=x->right; else x=x->left; if (x==NULL) break; } return x; } void insert(int key) { bool lr; if (root==NULL) { make_node(root); root->key=key; return ; } x=root; while (x!=NULL) { y=x; if (key>x->key) { x=x->right; lr=1; } else { x=x->left; lr=0; } } make_node(w); w->p=y; w->key=key; if (lr) y->right=w; else y->left=w; } void build(int *s,int n) { int i; #if 0 int a,b; for (i=0;i<n;i++) { srand((int)time(0)); a=rand()%n; b=rand()%n; swap(s[a],s[b]); } #endif for (i=0;i<n;i++) insert(s[i]); } void del(int key) { if (empty()) { printf("The tree is empty!!/n"); return ; } y=search(key); if (y==NULL) { printf("No such node!!/n"); return ; } if (y==root && y->right==NULL) { root=y->left; delete y; return ; } if (y==root && y->left==NULL) { root=y->right; delete y; return ; } w=y; if (y->left!=NULL && y->right!=NULL) y=search(suc(key)); x=y->left; if (x==NULL) x=y->right; if (x!=NULL) x->p=y->p; if (y!=root) { if (y==y->p->right) y->p->right=x; else y->p->left=x; } if (y!=w) w->key=y->key; delete y; } int max() { if (empty()) { printf("The tree is empty!!/n"); return 0; } node *x=root; while (x->right!=NULL) x=x->right; return x->key; } int min() { if (empty()) { printf("The tree is empty!!/n"); return 0; } node *x=root; while (x->left!=NULL) x=x->left; return x->key; } int suc(int key) { if (empty()) { printf("The tree is empty!!/n"); return 0; } x=search(key); if (key==max()) { printf("It's already the max number!!/n"); return 0; } if (x==NULL) { printf("No such number in the tree!!/n"); return 0; } if (x->right!=NULL) { x=x->right; while (x->left!=NULL) x=x->left; } else { y=x->p; while (y->left!=x) { x=y; y=y->p; } x=y; } return x->key; } int pre(int key) { if (empty()) { printf("The tree is empty!!/n"); return 0; } x=search(key); if (key==min()) { printf("It's already the min number!!/n"); return 0; } if (x==NULL) { printf("No such number in the tree!!/n"); return 0; } if (x->left!=NULL) { x=x->left; while (x->right!=NULL) x=x->right; } else { y=x->p; while (y->right!=x) { x=y; y=y->p; } x=y; } return x->key; } int left_son(int key) { if (empty()) { printf("The tree is empty!!/n"); return 0; } if (search(key)==NULL) { printf("No such node!!/n"); return 0; } x=search(key)->left; if (x==NULL) { printf("This node doesn't have left son!!/n"); return 0; } else return x->key; } int right_son(int key) { if (empty()) { printf("The tree is empty!!/n"); return 0; } if (search(key)==NULL) { printf("No such node!!/n"); return 0; } x=search(key)->right; if (x==NULL) { printf("This node doesn't have right son!!/n"); return 0; } else return x->key; } void l_rotate(int key) { if (empty()) { printf("The tree is empty!!/n"); return ; } x=search(key); if (x->right==NULL) { printf("It can't left-rotate!!/n"); return ; } else { w=x->right; w->p=x->p; if (x->p!=NULL) { if (x==x->p->right) x->p->right=w; else x->p->left=w; } x->p=w; x->right=w->left; w->left=x; if (w->left!=NULL) w->left->p=x; if (x==root) root=w; } } void r_rotate(int key) { if (empty()) { printf("The tree is empty!!/n"); return ; } x=search(key); if (x->left==NULL) { printf("It can't right-rotate!!/n"); return ; } else { w=x->left; w->p=x->p; if (x->p!=NULL) { if (x==x->p->right) x->p->right=w; else x->p->left=w; } x->p=w; x->left=w->right; w->right=x; if (w->right!=NULL) w->right->p=x; if (x==root) root=w; } } void front_print(node *temp) { if (empty()) { printf("The tree is empty!!/n"); return ; } if (temp!=NULL) { printf("%d ",temp->key); front_print(temp->left); front_print(temp->right); } } void middle_print(node *temp) { if (empty()) { printf("The tree is empty!!/n"); return ; } if (temp!=NULL) { middle_print(temp->left); printf("%d ",temp->key); middle_print(temp->right); } } void behind_print(node *temp) { if (empty()) { printf("The tree is empty!!/n"); return ; } if (temp!=NULL) { behind_print(temp->left); behind_print(temp->right); printf("%d ",temp->key); } } void cut(node *temp) { if (empty()) { printf("The tree is empty!!/n"); return ; } if (temp!=NULL) { cut(temp->left); cut(temp->right); if (temp->p!=NULL) { if (temp->p->right==temp) temp->p->right=NULL; else temp->p->left=NULL; } if (temp==root) root=NULL; delete temp; } } inline node* get_root() {return root;} inline bool empty(){return root==NULL;} BST () {root=NULL;} ~BST (){} };
可以复制落电脑度玩下d左旋右旋ge~~~有bug提醒我窝{OTZ}
最后为杭电OJ ge速度感到悲哀……
发表评论
-
HDU 1075 What Are You Talking About
2011-08-04 11:00 835What Are You Talking About Tim ... -
HDU 1022 Train Problem I
2011-08-02 21:00 998Train Problem I Time Limit: 20 ... -
HDU 3791 二叉搜索树
2011-08-02 14:26 1163二叉搜索树 Time Limit: 20 ... -
PKU 2352 Stars
2011-07-31 21:47 989Stars Time Limit: 1000MS ... -
PKU 2774 Long Long Message
2011-07-31 21:26 865Long Long Message Time Li ... -
PKU 2777 Count Color
2011-07-31 21:31 769Count Color Time Limit: 1 ... -
ZOJ 3512 Financial Fraud .
2011-07-31 20:49 1233Financial Fraud Time Limit: 3 ... -
PKU 1177 Picture .
2011-07-31 19:54 803Picture Time Limit: 20 ... -
HDU 1272 小希的迷宫 .
2011-07-31 19:26 979Problem Description 上次Gardon的迷宫 ... -
基数树,赵元松+左儿子右兄弟版(白话文) .
2011-07-31 19:23 970今日系我第一日种树兼第一日整一个类第一次做数据结构小扩展,真系 ... -
试一下说明RB-Delete-Fixed .
2011-07-31 19:21 599Red-Black-Tree又叫红黑树 ...
相关推荐
PySpark 机器学习、自然语言处理与推荐系统配套代码+数据集.zipPySpark 机器学习、自然语言处理与推荐系统配套代码+数据集.zipPySpark 机器学习、自然语言处理与推荐系统配套代码+数据集.zipPySpark 机器学习、自然...
《茶经》白话文.pdf
白话文运动的危机,CAJViewer 文件,使用CAJViewer软件查看
计算机考研数据结构,含各种疑难点讲解,常见考点。 (当然应付数据机构的期末考试更是绰绰有余了。 严蔚敏老师讲的数据结构的课本,很经典的课程。) 帮助你快速的复习,更快的解决题目。总结均是刷了多年的题写...
白话机器学习的数学-立石贤吾-源代码.zip
《太上感应篇》原文以及白话文.docx
濒湖脉学(原文和白话文).doc
Backend system based on node.js + Mongodb. 基于 node.js + Mongodb
最全面的数据结构算法及重要的排序算法
白话文的发展史.doc
java课程设计作业——基于java实现的扫雷游戏(源码+设计说明文档+可执行文件),直接点击“扫雷.exe”即可运行 --利用swing做出的扫雷桌面游戏,运行时直接双击可执行文件夹下的“扫雷.exe”即可 java课程设计...
pyhton深度学习课程设计——基于Tensorflow与Flask结合打造手写体数字识别项目(含源码+数据集+说明文档) 使用tensorflow框架,构建回归和CNN两种模型,对手写数字体进行识别 开发环境 Python:3.7 Tensorflow: ...
基于springboot+thymeleaf+mybatis+tale.js+redis简洁的个人博客系统源码,适合快速全栈学习,项目经过严格测试,确保可以运行! 1.涉及技术及工具 核心框架:SpringBoot ORM 框架:MyBatis MyBatis 工具:MyBatis...
这个项目是我学习 Vue2.0+Node.js+MongoDB全栈打造商城系统 的代码仓库.zip
UDS,统一诊断服务,是诊断服务的规范化标准,一般基于CAN总线测试。主机厂会根据自身需求定义不同的诊断规范。本文章是介绍UDS服务的白话文,极其适合刚接触UDS的小白,作为学习入门的标准手册之一。
Vue3+express+node.js+elementPlus+vue-router+vuex+mysql+axios实现商城后台管理系统
《僧伽吒经》+白话全文注释版(第三卷下)[文].pdf
基于 vite3.x + vue3.x + antd-design-vue3.x + typescript4.x 基础的后台管理系统模板
机器学习实践案例,mnist数据集,KNN算法分类、决策树分类Iris数据集、朴素贝叶斯分类西瓜数据集、逻辑斯蒂回归,随机梯度 mnist数据集,KNN算法分类。 决策树分类Iris数据集(鸢尾花)。 朴素贝叶斯分类西瓜数据集...
后台管理系统,react+node.js+mongoDB; .zip