Forum Navigation
You need to log in to create posts and topics.

Re: Re: Getting the Max number from a set of numbers

Posted by: richlove <richlove@...>

Ken, thanks for that solution.

 

I also used Brian’s sort routine and trimmed it down to a simple example:

 

 

include "NSLog.incl"

 

toolbox qsort( pointer array, unsigned long nmembers, unsigned long member_size, ptr compar )

 

local fn ComparisonCallbackForQsort( ap as ptr, bp as ptr )

long   result = 0

 

if ( ap.0& > bp.0& ) then result = NSOrderedDescending  : exit fn

if ( ap.0& < bp.0& ) then result = NSOrderedAscending   : exit fn

end fn = result

 

// Main

window 1, @"Integer Sort", (0,0) - (550, 250)

 

long  gData(5)

 

// set these values to sort

gData(1) = 2

gData(2) = 44

gData(3) = 11

gData(4) = 99

gData(5) = 35

 

qsort( @gData(0), 6, sizeof( long ), @fn ComparisonCallbackForQsort )

 

printf @"Highest number is %ld", gData(5)

 

 

HandleEvents

 

 

 

Rich

 

 

 

 

From: <futurebasic@freegroups.net&gt; on behalf of Ken Shmidheiser <kashmidheiser@gmail.com&gt;
Reply-To: <futurebasic@freegroups.net&gt;
Date: Tuesday, April 5, 2022 at 7:01 PM
To: <futurebasic@freegroups.net&gt;
Subject: [FB] Re: Getting the Max number from a set of numbers

 

Back to Rich's original post in this thread he asked:

 

The following works in Objective-C

But how is this done in FutureBasic? (without using a C Function)

NSArray *unsortedArray = @[ @2, @44, @11, @99, @35 ];

NSNumber *maxNumber = [unsortedArray valueForKeyPath:@"@max.self"];

NSLog(@"%@&quot;, maxNumber); // 99

Here's the answer, I just wish I could claim this as my own. 😀

 

We took the long way around to get here, but it was fun!

 

Ken

 

include "NSLog.incl"

 

local fn DoIt

CFArrayRef unsortedArray = @[@2,@44,@99,@35]

CFNumberRef maxNumber = fn ObjectValueForKeyPath( (ObjectRef)unsortedArray, @"@max.self" )

NSLog(@"%@&quot;,maxNumber)

end fn

 

fn DoIt

 

HandleEvents

 

 

 

--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@freegroups.net To access the list archives, go to: http://freegroups.net/groups/futurebasic/