![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
二分搜索树
shaoweiah
这个作者很懒,什么都没留下…
展开
-
leetcode98--验证二叉搜索树(c++)
题目给定一个二叉树,判断其是否是一个有效的二叉搜索树。假设一个二叉搜索树具有如下特征:节点的左子树只包含小于当前节点的数。节点的右子树只包含大于当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。示例 1:输入: 2 / \ 1 3输出: true示例 2:输入: 5 / \ 1 4 / \ 3 6输出:...原创 2020-05-05 17:27:02 · 170 阅读 · 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 · 159 阅读 · 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 · 83 阅读 · 0 评论