Sorting algorithms/Bubble sort: Difference between revisions
→{{header|FutureBasic}}
No edit summary |
|||
Line 2,908:
local fn BubbleSort( array as CFMutableArrayRef ) as CFArrayRef
NSUInteger i, x, y, count = len(array)▼
BOOL swapped = YES▼
▲NSUInteger i, x, y, count = len(array)
▲BOOL swapped = YES
while (swapped)
for i = 1 to count -1▼
swapped = NO▼
x = fn NumberIntegerValue( array[i-1] )
▲for i = 1 to count -1
MutableArrayExchangeObjects( array, (i-1), i )▼
▲MutableArrayExchangeObjects( array, (i-1), i )
end if▼
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}}==
|