#include <iostream>
/* Insert Sort
basic idea: inserting records into sorted ordered tables
Features: A stable sequencing method, time complexity O (n^2)
*/
void insertsort (int array[],int len) {
int i,j;
int temp;
for (i =1; i < Len; i++) { //I:1 ~ &L T;len (i++)
temp = Array[i];
for (j = i-1; J >=0; j--) { J:i-1 ~ >=0 (j--)
if (temp < array[j]) { // Assuming the element to be inserted < previous sequence, the post-move element Vegetarian
array[j+1] = array[j];
}else{
break;
}
}
array[j+1] = temp; // vacancy fill in the element you want to insert.
}
}
int Main (int argc,constchar * argv[])
{
int i =0;
int a[] = {5,4,9,8 ,7,6,0,1,3 ,2};
int len =sizeof(a)/sizeof(a[0 ]);
// Insert Sort
insertsort(a,len);
for (i =0; i < Len; i++) {
printf("%d", A[i]);
}
printf("\ n");
return0;
}
Understanding the sorting algorithm in a comprehensible sort-insertion sort