冒泡排序优化版
冒泡排序优化,特记于此,铭记于心...
(从小到大)
1 //冒泡排序 2 DWORD Bubblesort( VOID* pArry, 3 const DWORD dwNum ) 4 { 5 DWORD dwRet; 6 dwRet = 0; 7 8 BOOL bFlag; 9 PDWORD dwP; 10 DWORD dwCount_I; 11 DWORD dwCount_J; 12 DWORD dwTemp; 13 14 15 bFlag = TRUE; 16 dwP = (PDWORD)pArry; 17 for ( dwCount_I = 0; dwCount_I < dwNum && bFlag; dwCount_I++ ) 18 { 19 bFlag = FALSE; 20 for ( dwCount_J = 0; dwCount_J < ( dwNum - dwCount_I - 0x01 ); dwCount_J++ ) 21 { 22 if( dwP[dwCount_J] > dwP[dwCount_J + 0x01] ) 23 { 24 dwTemp = dwP[dwCount_J]; 25 dwP[dwCount_J] = dwP[dwCount_J + 0x01]; 26 dwP[dwCount_J + 0x01] = dwTemp; 27 bFlag = TRUE; 28 } 29 } 30 } 31 32 33 return dwRet; 34 }