Long time no review of the previous written data structure, today read a paragraph before the insertion sort.
Insertion sorting principle: Popular speaking, and playing poker cards is a truth, from a pile of Chaos card, a card, take one after the front row with the cards to compare, insert the appropriate position.
Complexity of Time: O (n^2)
/*Insert Sort 2.0** This version will create an array function to delete, * * Create an array with an insert sort orchestration into the same function. */#include"stdafx.h"#include<stdio.h>#defineM 1000voidInsert_sorting (intA[],intn);//Insert SortvoidOut_put (intA[],intn);//Output ArrayintMain () {intN; intA[m] = {0}; printf_s ("Enter the number to be sorted \ n"); printf_s ("n="); scanf_s ("%d", &N); Insert_sorting (A,n); Out_put (A, n); return 0;}voidInsert_sorting (intA[],intN) { intI, J, WEP;//WEP is intermediate variableprintf_s ("Please enter a 1th value ="); scanf_s ("%d", &a[0]); for(i =1; I < n; i++) {printf_s ("Please enter%d value =", i+1); scanf_s ("%d", &A[i]); for(j = i;; j--) { if(J = =0) { Break; } if(A[j] < a[j-1]) {WEP= A[j-1]; A[j-1] =A[j]; A[J]=WEP; } Else { Break; } } }}voidOut_put (intA[],intN) { inti; for(i =0; I < n; i++) {printf_s ("%d", A[i]); }}
Insert Sort 2.0