Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 2,908: | Line 2,908: | ||
local fn BubbleSort( array as CFMutableArrayRef ) as CFArrayRef |
local fn BubbleSort( array as CFMutableArrayRef ) as CFArrayRef |
||
⚫ | |||
'~'1 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
while (swapped) |
|||
swapped = NO |
|||
⚫ | |||
⚫ | |||
x = fn NumberIntegerValue( array[i-1] ) |
|||
⚫ | |||
y = fn NumberIntegerValue( array[i] ) |
|||
if ( x > y ) |
|||
⚫ | |||
if ( x > y ) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
swapped = YES |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end fn = array |
end fn = array |
||
Line 2,931: | Line 2,930: | ||
array = fn MutableArrayWithCapacity(0) |
array = fn MutableArrayWithCapacity(0) |
||
for i = 0 to 20 |
for i = 0 to 20 |
||
MutableArrayAddObject( array, fn NumberWithInteger( rnd(100) ) ) |
MutableArrayAddObject( array, fn NumberWithInteger( rnd(100) ) ) |
||
next |
next |
||
Line 2,939: | Line 2,938: | ||
NSLog( @"\n-----------------\nUnsorted : Sorted\n-----------------" ) |
NSLog( @"\n-----------------\nUnsorted : Sorted\n-----------------" ) |
||
for i = 0 to 20 |
for i = 0 to 20 |
||
NSLog( @"%8ld : %-8ld", fn NumberIntegerValue( unsortedArray[i] ), fn NumberIntegerValue( sortedArray[i] ) ) |
NSLog( @"%8ld : %-8ld", fn NumberIntegerValue( unsortedArray[i] ), fn NumberIntegerValue( sortedArray[i] ) ) |
||
next |
next |
||
Line 2,973: | Line 2,972: | ||
30 : 97 |
30 : 97 |
||
</pre> |
</pre> |
||
=={{header|g-fu}}== |
=={{header|g-fu}}== |