Python sort one insert sort
The first thing to do is insert sort, and the personal understanding is to take an element of the queue and compare it to its previous elements. The process of exchanging positions based on size okay, let's take a look at the code first.
First of all is an unordered list to print it so that after the sort has a comparison, and then I comment on the workflow, the following I came to one by one instructions under its running process, the first to declare an insert Sort function name Insert_sort, to pass the parameter to Lis,count to get the list of LIS length Len ( LIS), and then we're going to start writing the loop contrast for I in range (from 1 to the list length count) and then the number that is labeled as a position in the list (the LIS subscript defaults to start at 0 and then the ... J used to take the front of I a seat i-1 equals 0, which is used in a descending way to compare, j=0 into the loop, Judge Lis[0] that is 85 greater than 28, that is, the front of the number is larger than the number of the back of the exchange position, here is lis[0+1] lis[1]28 by lis[0] 85 is assigned (can be simply understood as a=1,b=0 if a>b a,b=b,a equivalent to a=0,b=1), J:0-1=-1 loop ends, of course, if you still do not clearly change the following code
First you want to comment the # code, and then at the end of the loop to print out each cycle of the results of the game can be seen clearly, here can be clearly seen in each cycle to change the previous number of the order of the first few numbers (pay particular attention to the position of the 11 change), in fact, each time to take K to go to the previous As long as the big position than K exchange. In the direct is compared with the previous number, as long as it is bigger than you change position. For example, you buy a car, see a lot of kinds, a go to find out a lot of things to match, shop around to ask to find this second home discount big, you want to buy the desire to increase, will be the first to buy the row in the back, priority second home, the results of the third one-stop service all with you, discount is good, At this time you will compare three of the most wanted to go to the front row, the bad is still behind a sequence of three-way.
Thanks for watching, see you next time.
Python sort one insert sort