Monday, December 14, 2015

Selection sort

void selection_sort ( vector < int > a ) {
    int min_index = -1;
    for (int i = 0; i < n - 1; i++) {
        min = i;
        for (int j = i+1; j< n; j++) {
            if (a[j] < min_index) {
                min_index =  j;
            }
        }
        int temp = a[i];
        a[i] = a[min_index];
        a[min_index] = temp;
    }

}

No comments: