Another way would be to create a query from the array and then just use
SQL to sort the data and then put the results from the query back into
the array.
Pete
>>> [EMAIL PROTECTED] 3/06/2005 8:12 am >>>
anything binary is logN, all the rest is fairly straigt foward n/2,
n^2, 2n etc
>>> [EMAIL PROTECTED] 06/03/05 10:06 am >>>
Hey Pat -
You got any online references handy on how to compute what the O() of
an algorithm is?
I can never remember how to do calculate the damn things, and I could
use the refresher.
Mark
On 6/3/05, Pat Branley <[EMAIL PROTECTED]> wrote:
> OK, i coded it properly now:
>
>
> <cfparam name="value" default="11" >
>
> <cfscript>
> function binarySearch(sortedArray, startIdx, endIdx, value)
> {
> arrayMid = int( (startIdx + endIdx) / 2 );
> if( sortedArray[arrayMid] EQ value) //found the value
> return arrayMid;
> else if ( sortedArray[arrayMid] GT value) //search left
> return binarySearch(sortedArray, startIdx, arrayMid-1,
value);
> else if ( sortedArray[arrayMid] LT value) //search right
> return binarySearch(sortedArray, arrayMid+1, endIdx,
value);
> else if ( startIdx GT endIdx ) //value not found.
> return -1;
> else
> return -2; //just in case i buggered something up.
> }
>
--
E: [EMAIL PROTECTED]
W: www.compoundtheory.com
ICQ: 3094740
---
You are currently subscribed to cfaussie as:
[EMAIL PROTECTED]
To unsubscribe send a blank email to
[EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to
[EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/
---
You are currently subscribed to cfaussie as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/