Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: RE: FLASH: Array.sort() performance?
From: Branden Hall
Date: Wed, 20 Dec 2000 20:36:51 GMT

Thanks Helen!
Actually, I released another version of it that addresses a bug in the
comparison operators with strings:

function Array_qSort(){
//Figure out if any arguments were passed in
//If there weren't set bot and top to default values
if (arguments[0]==null){
var bot = 0;
}else{
var bot = arguments[0];
}
if (arguments[1]==null){
var top = this.length-1;
}else{
var top = arguments[1];
}
if (top-bot == 1){
if (this[top] lt this[bot]){
temp = this[top];
this[top] = this[bot];
this[bot] = temp;
}
}else{
//Set up loop for tail recursion
while (bot<top){
var i = bot;
var j = top;

//Pick the pivot
pivot = this[bot];

//Partition the array around the pivot
while(i<j){
while(this[j] gt pivot){
--j;
}
this[i] = this[j];
while (i<j && ((this[i] lt pivot)||(this[i]
eq pivot))){
++i;
}
this[j]=this[i];
}

//Replace the pivot
this[i]=pivot;

//Sort the left sub array
this.qSort(bot,i-1);

//Sort the right sub array via tail recursion
bot = i+1;
}
}
}
Array.prototype.qSort = Array_qSort;

-= Branden J. Hall
-= Senior Interactive Developer/Instructor
-= Fig Leaf Software - "We've got you covered!"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flasher is generously supported by...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
flashforward2000 and the Flash(tm) Film Festival
November 27-29, 2000, LONDON, National Film Theatre

Produced by United Digital Artists and lynda.com
-Sponsored by Macromedia, Adobe Systems and Apple Computer
-http://www.flashforward2000.com or UK tel. +44 (0870) 751 1526
Register before November 10 and save �200
http:// www.flashforward2000.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe or change your list settings go to
http://www.chinwag.com/flasher or email helpatchinwag [dot] com


Replies
  FLASH: millions of windows & server issu, olga

[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]