#include <bits/stdc++.h>
using namespace std;
void insertion_sort(int arr[] , int n)
{
for(int i=0;i<=n-1;i++){
int j = i;
while(j>0, arr[j-1] > arr[j])
{
int temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
j--;
}
}
}
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
insertion_sort(arr, n);
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter