Do one comparison and return one of two possible orders on it, but I need to decide that.
虽然可以做一次比较,然后返回两个可能的顺序中的一个为结果,但是这需要我来做决定。
So in fact, it is the case, if you look at data, and by the way, that's the way I ended up setting a lot of these parameters and playing with it, was comparing what my simulation said to historical stock data.
所以实际上,在这个例子中,如果你看到数据,顺便说一下,这就是我设置很多变量,然后编程的方式,也就是把我的仿真程序得到的结果,和历史股票数据进行比较。
It's probably just easier to have the idea there.
这样比较容易找到最终结果
I'm going to tort-- I'm going to make the font smaller so we can see more.
我们还没看到比较结果,好,你知道我要做什么了么?
It says, well I'm going to print out first and last just so you can see it, and then I say, gee 2 if last minus first is less than 2, that is, if there's no more than two elements left in the list, then I can just check those two elements and return the answer.
然后它计算了尾点和开始点的差,如果小于2的话,也就是说数组中的元素小于等于,我对这两个元素进行比较,然后返回结果就可以了,否则的话,我们就去寻找中值点,注意它是怎么实现的,首先这个指向一个列表的开头。
And if you just look at the numbers, you can see how it cuts in from one side and then the other side as it keeps narrowing that range until it gets down to the place where there are at most two things left, and then it just has to check those two to say whether it's there or not.
你能看到他是如何不断的,从一个大的范围被拦腰劈开,知道最终只剩下两个数字,然后就只需要,比一比就知道结果了,将它同线性查找比较下。
Initially, it's the beginning and the end of it.
然后根据中值点和目标数的比较结果。
应用推荐