well, void selectionSort(int arr[], int size);
void swap(int& x, int& y);
int main()
{
int numbers[] = { 13, 5, 1, 7, 9, 11, 3, 17, 19, 15 };
int k;
cout << "BEFORE SORT: ";
for (k = 0; k < MAXSIZE; k++)
cout << numbers[k] << " ";
selectionSort(numbers, MAXSIZE);
cout << endl << endl;
cout << "AFTER SORT: ";
for (k = 0; k < MAXSIZE; k++)
cout << numbers[k] << " ";
cout << endl << endl << endl;
system("PAUSE");
ret urn 0;
}// end main()
void selectionSort(int arr[], int size)
{
int indexOfMin, pass, j;
for (pass = 0; pass < size - 1; pass++)
{
indexOfMin = pass;
for (j = pass + 1; j < size; j++)
if (arr[j] < arr[indexOfMin])
indexOfMin = j;
swap(arr[pass], arr[indexOfMin]);
}
}// end selectionSort()
void swap(int& x, int& y)
{
int temp;
temp = x;
x = y;
y = temp;
}// end swap()
Answered by
Romi
, an ibibo Master,
at
9:07 PM on June 21, 2008