Algorithm Ideas
⒈ starting with the first element, the element can be thought to have been sorted ⒉ take out the next element, scan from backward forward in the ordered sequence of elements ⒊ if the element (sorted) is greater than the new element, move the element to the next position ⒋ repeat step 3 until the sorted element is found to be less than or equal to the position of the new element ⒌ Insert a new element into the next position ⒍ repeat step 2~5
IllustrationsThe process of sorting a column of numbers using an insert sort
C # code implementationIn order for everyone to copy them directly with me.
Private Static voidInsertsort (list<int>list) { for(inti =1; I < list. Count; i++) { intInservalue =List[i]; intInsertindex = i-1; while(Insertindex >=0&& Inservalue <List[insertindex]) {List[insertindex+1] =List[insertindex]; Insertindex--; } List[insertindex+1] =Inservalue; } }
Http://www.cnblogs.com/weiios/p/3933985.html
C # Insert sort in a detailed