Selection Sort

void ssort(int *array, int size)
{
    int i, j, min;
    for (i = 0; i < size-1; i++) {
        min = i;
        for (j = i; j < size; j++) {
            if (array[j] < array[min])
                min = j;
        }
        swap(array, i, min);
    }
}

Time Complexity

Best / Avg / Worst:
O(n2)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License