We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
快速排序(Quick sort)是一个基于交换的排序算法,它采用分治的策略,所以也称其为分治排序。
算法分析:
function quickSort(arr, left, right) { var len = arr.length, partitionIndex, left = typeof left != 'number' ? 0 : left, right = typeof right != 'number' ? len - 1 : right; if (left < right) { partitionIndex = partition(arr, left, right); quickSort(arr, left, partitionIndex-1); quickSort(arr, partitionIndex+1, right); } return arr; } // 分区操作 function partition(arr, left, right) { // 设定基准值(pivot) var pivot = left, index = pivot + 1; for (var i = index; i <= right; i++) { if (arr[i] < arr[pivot]) { swap(arr, i, index); index++; } } swap(arr, pivot, index - 1); return index-1; } function swap(arr, i, j) { var temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
快速排序
快速排序(Quick sort)是一个基于交换的排序算法,它采用分治的策略,所以也称其为分治排序。
算法分析:
The text was updated successfully, but these errors were encountered: