Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function quickSort(t){
- _quickSort(t,0,t.length-1,0,t.length-1);
- }
- function _quickSort(t, s, e, sp, ep){
- if( s>=e ){
- return;
- }
- while( sp<ep && t[sp]<t[e] ){
- sp++;
- }
- if( sp==e ){
- _quickSort(t,s,e-1,s,e-1);
- }
- else{
- while(t[ep]>=t[e] && sp<ep ){
- ep--;
- }
- if( sp==ep ){
- var temp = t[sp];
- t[sp] = t[e];
- t[e] = temp;
- if( s!=sp ){
- _quickSort(t,s,sp-1,s,sp-1);
- }
- _quickSort(t,sp+1,e,sp+1,e);
- }else{
- var temp = t[sp];
- t[sp] = t[ep];
- t[ep] = temp;
- _quickSort(t,s,e,sp+1,ep);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment