选择排序

include

using namespace std;
//Function prototype
int* selectSort(int ,int);
void showArray(const int [],int);
int main()
{
int array[] = {7,2,4,5,9,10};
int size = sizeof(array)/sizeof(array[0]);
showArray(array,size);
selectSort(array,size);
showArray(array, size);
cout < return 0;
}
int
selectSort(int p,int size)
{
int startScan, minIndex, minValue;
for (startScan = 0;startScan<(size-1);startScan++)
{
minIndex = startScan;
minValue =
(p+startScan);
for (int index = startScan+1;index {
if ((p+index) {
minValue =
(p + index);
minIndex = index;
}

    }
    *(p + minIndex) = *(p + startScan);
    *(p + startScan) = minValue;
}
return p;

}
void showArray(const int array[], int size)
{
for (int count=0;count {
cout << array[count] <<" ";
}
cout << endl;
}

你可能感兴趣的:(选择排序)