Insertion Sort
Easyjavapythonccppjavascript
Sort an integer array in ascending order using Insertion Sort — take each element and insert it into its correct position among the elements already sorted. The judge checks the final sorted output.
Input Format
The first line contains an integer N. The second line contains N space-separated integers.
Output Format
Print the N integers in ascending order, separated by single spaces, on one line.
Example 1
Input
5 5 2 4 6 1
Output
1 2 4 5 6
Explanation: Each element is inserted into its correct place among the sorted prefix.
- 1 <= N <= 100000
- -1000000000 <= A[i] <= 1000000000