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
It is a good way to patition a deduplicated array , but if the unsorted array is [1,2,3,4,4,4,2,4,4,6,7], the function can't move 2 to front.
[1,2,3,4,4,4,2,4,4,6,7]
2
I'd like to write a patition function like this:
function partition(array, left, right, compareFn) { const pivot = array[Math.floor((right + left) / 2)]; let l = left; let r = right; let i = left; while (i <= r) { if (compareFn(array[i], pivot) === Compare.LESS_THAN) { swap(array, i, l); i++; l++; } else if (compareFn(array[i], pivot) === Compare.BIGGER_THAN) { swap(arr, i, r); r--; } else { i++; } } // return [l, r]; return l; }
PS:I learned a lot from your book, thank you~
The text was updated successfully, but these errors were encountered:
No branches or pull requests
It is a good way to patition a deduplicated array , but if the unsorted array is
[1,2,3,4,4,4,2,4,4,6,7]
, the function can't move2
to front.I'd like to write a patition function like this:
PS:I learned a lot from your book, thank you~
The text was updated successfully, but these errors were encountered: