P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Array
:
Quick sort algorithm
author:
flash.etc
[+]
,
Submitted: 08.05.01 5p
// This is a generic version of C.A.R Hoare's Quick Sort algorithm. // // Description :: Quick Sort // // Author :: André Vallières // Array.prototype.qSort = function ( low0, high0 ) { var low = low0; var high = high0; var mid; if ( high0 > low0) { mid = this[ Math.round( ( low0 + high0 ) / 2 ) ]; while( low <= high ) { while ( ( low < high0 ) and ( this[low] < mid ) ) { low++; } while ( ( high > low0 ) and ( this[high] > mid ) ) { high--; } if( low <= high ) { T = this[low]; this[low] = this[high]; this[high] = T; low++; high--; } } if ( low0 < high ) { this.qSort ( low0, high ); } if ( low < high0 ) { this.qSort ( low, high0 ); } return this; } }
usage
anyArray.qSort ( 0, anyArray.length - 1 );
msg
1
{
hantarex
[+]
, posted: 10.22.01 7a•-, top
[^]
}
It seems to be only usefull for sorting parts of an array because doesn't improve performances:
Try the embedded method:
startime = getTimer(); anyArray.sort(); totaltime = getTimer()-startime;
or this one:
startime = getTimer(); anyArray.qSort(0, anyArray.length - 1); totaltime = getTimer()-startime;
I've got slight performance differences between sort and qSort...
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@