Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The function patition for quickSort can't support array which has duplicates. #202

Open
@SikyChen

Description

@SikyChen

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:

functionpartition(array,left,right,compareFn){constpivot=array[Math.floor((right+left)/2)];letl=left;letr=right;leti=left;while(i<=r){if(compareFn(array[i],pivot)===Compare.LESS_THAN){swap(array,i,l);i++;l++;}elseif(compareFn(array[i],pivot)===Compare.BIGGER_THAN){swap(arr,i,r);r--;}else{i++;}}// return [l, r];returnl;}

PS:I learned a lot from your book, thank you~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp