So wherever the largest element started out in the list, by the time I get through it, it's at the end.
所以无论最大的元素,在列表的什么位置。
And the last piece of this, is as said, I have to make sure I know what my primitive elements are, in terms of operations.
最后,正如我们所说,我们要确定我们的基本元素是什么,以便于操作,我希望大家可以学习到。
So what is this, which element did I chart here?
那么这是什么,我画的这是哪个元素?
So the first one here is something called insertion sort which amounts to going through the list, taking the first thing that you see and inserting that element into its correct place, - then moving on to the next one, dealing with what element-- whatever element you're given and putting it in its right place.
首先是插入排序,在此算法中,需要遍历整个列表,将你遇到的第一个元素放在其正确的位置,然后移动到下一个元素,继续处理-,不管是什么元素,都将其插入到合适的位置。
At the end of the first round, I've got the smallest element at the front. At the end of the second round, I've got the smallest two elements at the front, in fact I got all of them sorted out. And it actually runs through the loop multiple times, making sure that it's in the right form.
看看发生了什么,在第一轮结束后,我把最小的元素移到了前面,第二轮结束后,我把最小的,两个元素移到了前面,实际上,所有的元素都排好序了,实际上,这个算法运行了几次循环,确认下这是正确的形式。
What's this thing doing? It's walking along the list looking for the smallest thing in the back end of the list, keeping track of where it came from and swapping it with that spot in the list. All right?
这是在做什么?是在遍历列表,找列表后端最小的元素,跟踪它从哪里来的,然后同当前点的元素交换,明白了么?
We're going to call binary search, it's going to take the list to search and the element, but it's also going to say, here's the first part of the list, and there's the last part of the list, Well, it checks to see, is it bigger than two?
我们将要调用这个二分查找,它将会在列表里面搜索元素,假定这里是,列表的第一个元素,那里是列表的最后一个元素,代码内部到底做了什么?
It says, right. If j is-- well it says until j is at the less than the length of l-- it says, if min value is bigger than the thing I'm looking at I'm going to do something, all right?
只要j比长度l小,如果MinVal比我要找到元素大,我就要做些什么了,我们来遍历?
Basic idea, before I even look at the code, is pretty simple. If I've got a list that is sorted, in let's call it, just in increasing order, and I haven't said what's in the list, could be numbers, could be other things, for now, we're going to just assume they're integers.
我们可以说基本的思想是很简单的,如果我有一个排好序的数组,让我们认为这个数组是递增的吧,我并没说数组里元素是什么,可能是数字,也可能是其他的东西,现在我们假设是integer类型的数字吧,最简单的方式就是这么做了:
应用推荐