My notes on leetcode
Thursday, November 20, 2014
Quick sort
quicksort(A,p,r){
if (p<r){
q=partition(A,p,r);
quicksort(A,p,q-1);
quicksort(A,q+1,r);
}
}
partition(A,p,r){
i=p-1;
for(int j=p;j<r;j++){
if (A[j]<=A[r]){
swap(A[++i],A[j])
}
}
swap(A[i+1],A[r]);
return i+1;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment