All pastes #11855 Raw Edit

Something

public text v1 · immutable
#11855 ·published 2005-05-16 02:43 UTC
rendered paste body
#include "selectionSort.h"
int COMPARES;
int SWAPS;
void selectionSort(int numbers[], int array_size)
{
  int i, j;
  int min, temp;
  SWAPS=0;
  COMPARES=0;

  for (i = 0; i < array_size-1; i++)
  {
    min = i;
    for (j = i+1; j < array_size; j++)
    { 
      if (numbers[j] < numbers[min] & COMPARES++)
        min = j;
    }
    
    temp = numbers[i];
    numbers[i] = numbers[min];
    numbers[min] = temp;
    SWAPS++;
  }
}


THE RESULT:
3 6 17 15 13 15 6 12 9 1 2 7 10 19 3 6 0 6 12 16

0 2 1 6 3 3 6 6 6 9 7 12 10 12 13 15 15 17 16 19

Swaps:19
Comapres:190
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Swaps:19
Comapres:190
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Swaps:19
Comapres:190