#include <stdio.h> #define N 1000 int arr[N]; /* For a length of n Array of arr Perform insert sort */ void
insertionSort(int arr[], int n); /* Print length is n Array of arr */ void printArray(int arr[],
int n); int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf(
"%d", &arr[i]); } insertionSort(arr, n); printArray(arr, n); return 0; } /*
Print length is n Array of arr */ void printArray(int arr[], int n) { int i; for (i = 0; i < n; i
++) { printf("%d", arr[i]); if (i < n - 1) /* subscript 0..n-2 There is a space after each element */ printf(" ");
/* subscript n-1, That is, there is no space after the last element */ } printf("\n");/* Wrap a line after printing */ } void insertionSort(int
arr[], int n){ int tmp; for(int i=1; i<n; i++) { int tmp = arr[i]; for(int j=i-
1; j>=0; j--) { if(tmp<arr[j]) { int temp; temp = arr[j]; arr[j] = arr[j+1]; arr
[j+1] = temp; } } } }

Technology
Daily Recommendation