Selection Sort

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
328 B
3
Indexable
Never
void swap(int *x, int *y)
{
  int temp = *x;
  *x = *y;
  *y = temp;
}
void selectionSort(int arr[], int n)
{
   int i, j, min_id;
   for (i = 0; i < n-1; i++)
   {
      min_id=i;
      for (j = i+1; j < n; j++)
        if (arr[min_id] > arr[j])
          min_id=j;
        swap(&arr[i], &arr[min_id]);
    }
}