快速排序算法(C语言)
来源:互联网 发布:ubuntu snmp v3配置 编辑:程序博客网 时间:2024/05/20 06:23
//**********************************************************************************//快速排序算法//功能:对数组元素a[low]--a[high]进行排序//**********************************************************************************void QuickSort(DataType a[], int low, int high){ int i = low, j = high; DataType temp = a[low]; if (low >= high) { return; } while (i < j) { while (i < j && temp.key <= a[j].key ) { j--;//在数组的右端扫描 } if (i < j) { a[i] = a[j]; i++; } while (i < j && a[i].key < temp.key) { i++;//在数组的左端扫描 } if (i < j) { a[j] = a[i]; j--; } } a[i] = temp; if (low < i) { QuickSort(a, low, i - 1);//对左端子集合进行递归 } if (i < high) { QuickSort(a, j + 1, high);//对右端子集合进行递归 }}