Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
No edit summary
Line 1,766: Line 1,766:
UK Boston
UK Boston
</pre>
</pre>

===Translation of Pseudocode===
This version is a direct implementation of this task's pseudocode.
<lang NetRexx>/* NetRexx */
options replace format comments java crossref savelog symbols binary

placesList = [String -
"UK London", "US New York" -
, "US Boston", "US Washington" -
, "UK Washington", "US Birmingham" -
, "UK Birmingham", "UK Boston" -
]
sortedList = bubbleSort(String[] Arrays.copyOf(placesList, placesList.length))

lists = [placesList, sortedList]
loop ln = 0 to lists.length - 1
cl = lists[ln]
loop ct = 0 to cl.length - 1
say cl[ct]
end ct
say
end ln

return

method bubbleSort(item = String[]) public constant binary returns String[]

hasChanged = boolean
itemCount = item.length
loop label h_ until \hasChanged
hasChanged = isFalse
itemCount = itemCount - 1
loop index = 0 to itemCount - 1
if item[index].compareTo(item[index + 1]) > 0 then do
swap = item[index]
item[index] = item[index + 1]
item[index + 1] = swap
hasChanged = isTrue
end
end index
end h_

return item

method isTrue public constant binary returns boolean
return 1 == 1

method isFalse public constant binary returns boolean
return \isTrue
</lang>


=={{header|Objeck}}==
=={{header|Objeck}}==