1 数据结构的练习与巩固 2 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 3 //折半搜索 4 int Quick_Search(int List[], int Length, int Number) 5 { 6 int Low, High, Middle; 7 Low = 0; 8 High = Length-1; 9 10 while (High >= Low) 11 { 12 Middle = (Low + High) / 2; 13 if (List[Middle] == Number) 14 return Middle; 15 if (List[Middle] < Number) 16 Low = Middle + 1; 17 if (List[Middle] > Number) 18 High = Middle - 1; 19 } 20 return -1; 21 } 22 23 //快速排序 24 void Quick_Sort(int List[], int Low, int High) 25 { 26 int i, j; 27 i = Low; 28 j = High; 29 int Key = List[Low]; 30 31 if(Low < High) 32 { 33 while (j > i) 34 { 35 while (List[j] >= Key && j > i) 36 j--; 37 if (j > i) 38 List[i++] = List[j]; 39 40 while (List[i] < Key && j > i) 41 i++; 42 if (j > i) 43 List[j--] = List[i]; 44 } 45 List[i] = Key; 46 47 Quick_Sort(List, Low, i - 1); 48 Quick_Sort(List, i + 1, High); 49 } 50 }