Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
...
分类:
其他好文 时间:
2014-12-04 13:59:41
阅读次数:
154
先上二叉树查找树的删除的代码,因为删除是二叉查找树最复杂的操作:
int BinarySearchTree::tree_remove(const T& elem)
{
BinarySearchTreeNode *z = tree_search(elem);//根据元素查找到要删除的节点
BinarySearchTreeNode *x, *y;
if (z != NULL)
{
...
分类:
编程语言 时间:
2014-12-04 08:51:29
阅读次数:
209
#include
#include
using namespace std;
int a[10000];
int Serch(int x,int y,int v)//二分查找下界当找不到的时候返回的是第一个大于,因为当出现a[x]小于v的时候,a[y]大于v的时候,x=(y+x)/2,程序会执行else,所以返回的时候就是y的值;
{
int mid;
while(x...
分类:
其他好文 时间:
2014-12-03 21:32:43
阅读次数:
158
今天CSDN博客发生异常,折腾了大半天终于发出了这篇博文。
【题目】
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only no...
分类:
其他好文 时间:
2014-12-03 17:14:52
阅读次数:
219
转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html*******************************************************************************简单题(包括枚举,二分查找,(复...
分类:
其他好文 时间:
2014-12-03 16:59:46
阅读次数:
456
二分查找:
1:大于等于xx的第一个数
int bin_s(int xx)
{
int l=1,r=10;
int ans=-1;
while(l>1;
if(a[m]>=xx) ans=m,r=m-1; //!!!...
分类:
其他好文 时间:
2014-12-03 00:34:03
阅读次数:
164
1. HashMap的数据结构数据结构中有数组和链表来实现对数据的存储,但这两者基本上是两个极端。数组数组存储区间是连续的,占用内存严重,故空间复杂的很大。但数组的二分查找时间复杂度小,为O(1);数组的特点是:寻址容易,插入和删除困难;链表链表存储区间离散,占用内存比较宽松,故空间复杂度很小,但时...
分类:
其他好文 时间:
2014-12-01 19:04:52
阅读次数:
339
题目描述:
将1-9这九个数字排成三行三列,使其行列、对角线上三数之和均相同,试编程求所有的可能;
#include
using namespace std;
int a[3][3], b[3][3];
int main()
{
int i, tx, ty;
int x = 0, y = 1;
a[0][1] = 1; ...
分类:
其他好文 时间:
2014-12-01 12:56:00
阅读次数:
263
Pat1057 树状数组求中位数,这题还有结合二分查找,不然后超时#include #include #include #include using namespace std; #define lowbit(x) x&(-x) #define N 100010 int c[N]; ...
分类:
编程语言 时间:
2014-12-01 10:04:15
阅读次数:
256
STL中关于二分查找的函数有三个lower_bound 、upper_bound 、binary_search 。这三个函数都运用于有序区间(当然这也是运用二分查找的前提),下面记录一下这两个函数。ForwardIter lower_bound(ForwardIter first, ForwardI...
分类:
编程语言 时间:
2014-12-01 00:42:59
阅读次数:
257