
二分搜索树
shaoweiah
这个作者很懒,什么都没留下…
展开
-
leetcode98--验证二叉搜索树(c++)
题目 给定一个二叉树,判断其是否是一个有效的二叉搜索树。 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数。 节点的右子树只包含大于当前节点的数。 所有左子树和右子树自身必须也是二叉搜索树。 示例 1: 输入: 2 / \ 1 3 输出: true 示例 2: 输入: 5 / \ 1 4 / \ 3 6 输出:...原创 2020-05-05 17:27:02 · 213 阅读 · 0 评论 -
二分搜索树c++数据结构
#include <iostream> using namespace std; // 二分搜索树 template <typename Key, typename Value> class BST{ private: // 二分搜索树中的节点为私有的结构体, 外界不需要了解二分搜索树节点的具体实现 struct Node{ Key k...原创 2020-04-30 14:21:07 · 198 阅读 · 0 评论 -
二分查找
迭代 template<typename T> int binarySearch(T arr[], int n, T target){ // 在arr[l...r]之中查找target int l = 0, r = n-1; while( l <= r ){ //int mid = (l + r)/2; // 防止极端情...原创 2020-04-30 14:12:32 · 111 阅读 · 0 评论