Data update
This commit is contained in:
parent
52a6ef48dd
commit
157b70a810
604 changed files with 14253 additions and 2100 deletions
28
Task/Binary-search/FutureBasic/binary-search-2.basic
Normal file
28
Task/Binary-search/FutureBasic/binary-search-2.basic
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
NSInteger local fn BinarySearch( array as CFArrayRef, key as CFTypeRef )
|
||||
NSInteger lo = 0
|
||||
include "NSLog.incl"
|
||||
|
||||
NSInteger local fn BinarySearch( array as CFArrayRef, key as CFTypeRef, range as CFRange )
|
||||
if ( range.length == 0 ) then return NSNotFound
|
||||
|
||||
NSInteger i = range.location + range.length / 2
|
||||
CFTypeRef midVal = array[i]
|
||||
|
||||
select ( fn NumberCompare( midVal, key ) )
|
||||
case NSOrderedAscending
|
||||
return fn BinarySearch( array, key, fn CFRangeMake( i + 1, range.length - i + 1 ) )
|
||||
case NSOrderedDescending
|
||||
return fn BinarySearch( array, key, fn CFRangeMake( range.location, i - range.location ) )
|
||||
end select
|
||||
end fn = i
|
||||
|
||||
void local fn DoIt
|
||||
CFArrayRef a = @[@1, @3, @4, @5, @6, @7, @8, @9, @10]
|
||||
NSLog(@"6 is at position %d", fn BinarySearch( a, @6, fn CFRangeMake(0,len(a)) )) // prints 4
|
||||
end fn
|
||||
|
||||
fn DoIt
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue