/*! @function ******************************************************************************** <PRE> 函数名 : SelectionSort 功能 : 选择排序 参数 : int count, 待排序数个数,double * sortNumber,待排序数组 返回值 : void 抛出异常 : -------------------------------------------------------------------------------- 备注 : 典型用法 : SelectionSort(count, randomNumber); -------------------------------------------------------------------------------- 作者 : <e.Chen> </PRE> *******************************************************************************/ void SelectionSort(int count, double * sortNumber) { DWORD startTime = GetTickCount(); int i = 0, j = 0; double key = 0.0 ; int keyIndex = 0; for (j = 0; j < count-1; j++) { i = j+1; key = sortNumber[j]; while (i < count) { if (key > sortNumber[i]) { key = sortNumber[i]; keyIndex = i; } i++; } sortNumber[keyIndex] = sortNumber[j]; sortNumber[j] = key; } //display the result //cout<<"Selection Sort: "; //for (i = 0; i < count; i++) //{ // cout<<sortNumber[i]<<" "; //} //cout<<endl; cout<<"Time Consumed: "<<GetTickCount() - startTime<<" ms"<<endl; }