So if I got these two cells they would be less they would have less potential than these.
因此这些细胞它们会,它们拥有的潜能就会比较少
If there are less than two elements there I just check one or both of those to see if I'm looking for the right thing.
列表里是否剩余超过两个元素?,是否剩余不足两个元素,这里面我就挑一两项来检查下是否运行正常。
So the take away is that if the user actually gives me two or three or four or whatever, this is this expression "is n less than 1" is going to evaluate to false if it's actually two or three or four or whatever.
所以先不管用户实际上给我,3,4还是其他数,这个表达式,“是否n小于1“将被评估为错误的,如果输入额是2,3,4或其它的数。
So first of all, I've got to be careful about the end test. But the second thing is, OK, if it stops whenever this is less than two, am I convinced that this will always halt?
小心最后一次比较,其次,如果少于两个元素程序停止了,我们能确信这总是应该终止的么?,答案是肯定的,因为我在做什么?
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的话,也就是说数组中的元素小于等于,我对这两个元素进行比较,然后返回结果就可以了,否则的话,我们就去寻找中值点,注意它是怎么实现的,首先这个指向一个列表的开头。
So this line or these lines of code up here are arguably constant time steps to say if N is less than 2 in return, that it will always take maybe one step, maybe two steps, some number of fixed CPU cycles.
如果N小于2并返回,那么这些行所对应的代码,通常只需要执行一步,或者两步,具体数字与CPU周期有关。
So if N is not less than 2, that is I have two elements or more in which case there's definitely some sorting to be done.
因此如果N不小于2,也就是有2个或更多的元素,那当然是需要做排序的。
应用推荐