Sorting algorithms/Bubble sort: Difference between revisions

No edit summary
Line 2,908:
 
local fn BubbleSort( array as CFMutableArrayRef ) as CFArrayRef
NSUInteger i, x, y, count = len(array)
'~'1
BOOL swapped = YES
NSUInteger i, x, y, count = len(array)
BOOL swapped = YES
while (swapped)
 
while ( swapped) = NO
for i = 1 to count -1
swapped = NO
x = fn NumberIntegerValue( array[i-1] )
for i = 1 to count -1
x y = fn NumberIntegerValue( array[i-1] )
y = fn NumberIntegerValue if ( array[i]x > y )
MutableArrayExchangeObjects( array, (i-1), i )
if ( x > y )
swapped = NOYES
MutableArrayExchangeObjects( array, (i-1), i )
end if
swapped = YES
next
end if
wend
next
wend
end fn = array
 
Line 2,931 ⟶ 2,930:
array = fn MutableArrayWithCapacity(0)
for i = 0 to 20
MutableArrayAddObject( array, fn NumberWithInteger( rnd(100) ) )
next
 
Line 2,939 ⟶ 2,938:
NSLog( @"\n-----------------\nUnsorted : Sorted\n-----------------" )
for i = 0 to 20
NSLog( @"%8ld : %-8ld", fn NumberIntegerValue( unsortedArray[i] ), fn NumberIntegerValue( sortedArray[i] ) )
next
 
Line 2,973 ⟶ 2,972:
30 : 97
</pre>
 
 
 
 
 
 
 
 
=={{header|g-fu}}==
715

edits