what is a selection sort code example
Example 1: selection sort
#include
using namespace std;
void selectionSort(int arr[], int n){
int i,j,min;
for(i=0;i
Example 2: selection sort
// C algorithm for SelectionSort
void selectionSort(int arr[], int n)
{
for(int i = 0; i < n-1; i++)
{
int min = i;
for(int j = i+1; j < n; j++)
{
if(arr[j] < arr[min])
min = j;
}
if(min != i)
{
// Swap
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
}