#include <bits/stdc++.h> using namespace std; void selection_sort(int arr[], int n) { for(int i=0;i<=n-2;i++) { int mini = i; for(int j=i;j<=n-1;j++) { if(arr[mini] > arr[j]) mini = j; } int temp = arr[mini]; arr[mini] = arr[i]; arr[i] = temp; } } int main() { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } selection_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