class Solution { public: int select(int arr[], int i) { int max = arr[0], ind = 0; int j; for ( j=1; j<=i; j++) { if (arr[j] > max) { ind = j; max = arr[j]; } } return ind; } void selectionSort(int arr[], int n) { int i, j; for (i = n-1; i >=0; i--) { int j = select(arr, i); swap(&arr[i], &arr[j]); } } };
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