#include #include // Sort an array using Insertion Sort void printArray(int a[], int n) { int i; printf("\nIndex i: "); for(i=0; i< n; i++) printf("%2d, ", i); printf("\nElement a[i]: "); for(i=0; i< n; i++) printf("%2d, ", a[i]); printf("\n\n"); } #define N 6 int main() { int a[N]= { 23, 78, 45, 8, 32, 56}; int i; printArray(a, N); // Print the unsorted array for(i = 1; i < N; i++) { int j = i; int INS = a[i]; while ((j > 0) && (a[j-1] > INS)) { a[j] = a[j-1]; // shift elements to the right j--; } a[j] = INS; // insert the element } printArray(a, N); // Print the sorted array system("pause"); }