5.3.4—二叉查找树—Convert Sorted Array to Binary Sear Tree
来源:互联网 发布:mmd双人动作数据 编辑:程序博客网 时间:2024/06/08 14:33
描述
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
#include "BinaryTree.h"#include<algorithm>#include<vector>#include<stack>using namespace std;vector<int> path;//===由有序数组构建BSTBinaryTreeNode *ConSortArrayToBST(int a[], int begin, int end){if (begin > end)return NULL;if (begin == end)return CreateBinaryTreeNode(a[(begin + end) / 2]);int mid = (begin + end) / 2;BinaryTreeNode *proot = CreateBinaryTreeNode(a[mid]);ConnectTreeNodes(proot, ConSortArrayToBST(a, begin, mid-1), ConSortArrayToBST(a, mid + 1, end));return proot;}int main(){const int n = 7;int a[n] = { 1, 3, 5, 7, 9, 11, 13 };int begin = 0;int end = n - 1;BinaryTreeNode *proot = ConSortArrayToBST(a, begin, end);PrintTree(proot);//===DestroyTree(proot);}
阅读全文
0 0
- 5.3.4—二叉查找树—Convert Sorted Array to Binary Sear Tree
- 5.3.5—二叉查找树—Convert Sorted List to Binary Sear Tree
- 5.3.5 Convert Sorted List to Binary Sear Tree
- 5.3.3—二叉查找树—Validate Binary Sear Tree
- 根据有序数组构造二叉查找树 Convert Sorted Array to Binary Search Tree
- Convert Sorted Array to Binary Search Tree 将数组转换成二叉查找树
- Leetcode 108 Convert Sorted Array to Binary Search Tree 有序数组构造平衡二叉查找树
- Leetcode#108. Convert Sorted Array to Binary Search Tree (平衡二叉查找树)
- 108. Convert Sorted Array to Binary Search Tree--二叉查找数
- 5.3.4 Convert Sorted Array to Binary Search Tree
- 5.3.4 Convert Sorted Array to Binary Search Tree
- 5.3.4 Convert Sorted Array to Binary Searh Tree
- Convert Sorted Array to Binary Search Tree (递增数组建高度平衡的二叉查找树)【leetcode】
- 108.leetcode Convert Sorted Array to Binary Search Tree(medium)[数组 二分查找 二叉平衡搜索树]
- LeetCode——Convert Sorted Array to Binary Search Tree
- Leetcode108——Convert Sorted Array to Binary Search Tree
- Algorithms—108.Convert Sorted Array to Binary Search Tree
- LeetCode108—Convert Sorted Array to Binary Search Tree
- 在我眼中vue/vux的钩子
- IOS与其他操作系统中静态库与动态库的用法总结
- 5.2.2—二叉树的构建—Construct Binary Tree from Inorder and Postorder Traversal
- 5.3.3—二叉查找树—Validate Binary Sear Tree
- [VC.NET]托管代码和非托管代码
- 5.3.4—二叉查找树—Convert Sorted Array to Binary Sear Tree
- 5.3.5—二叉查找树—Convert Sorted List to Binary Sear Tree
- 动态规划中级教程 343. Integer Break
- 大型复杂信息系统研发的大学式组织管理方法
- UVA11754 Code Feat
- 坦克大战学习笔记
- 5.4.1—二叉树的递归—Minimum Depth of Binary Tree
- opencv获取彩色(RGB)图像直方图
- Oracle SQL语句优化