Direct Insert Sort:
Algorithm steps:
1) Think of the first ordered column as the first ordinal sequence, the second element to the last element as an unordered sequence.
2) scan the unsorted sequence once from the head, inserting each element scanned into the appropriate position of the ordered sequence. (If the element you want to insert is equal to an element in an ordered sequence, insert the element you want to insert behind the equal element)
Algorithm:
Algorithm implementation:
public class Insertsort { void sort (int[] array) { for (int i = 1; i < Array.Length; i++) { //The data being marked for comparison int currentvalue = Array[i]; Int J; If the data in front of the data being labeled for comparison is larger than the tag data, move the data that is larger than the tagged data back one for (j = i-1; j > 0; j--) { if (CurrentValue < array[j]) {
array[j + 1] = Array[j]; } else {break ; } } ARRAY[J+1] = CurrentValue; } }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Insert sort directly