Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
→{{header|Yorick}}: Added zkl
(Added uBasic/4tH version) |
(→{{header|Yorick}}: Added zkl) |
||
Line 4,347:
}</lang>
=={{header|zkl}}==
<lang zkl>fcn bubbleSort(list){
itemCount := list.len();
do{
hasChanged := False;
foreach index in (itemCount -= 1){
if (list[index] > list[index + 1]){
list.swap(index,index + 1);
hasChanged = True;
}
}
}while(hasChanged);
list
}</lang>
Or, punting early termination:
<lang zkl>fcn bubbleSort2(list){
foreach n,index in ([list.len()-1..0,-1],n){
if (list[index] > list[index + 1]) list.swap(index,index + 1);
}
list
}</lang>
<lang zkl>bubbleSort2("This is a test".split("")).println();</lang>
{{out}}
<pre>L(" "," "," ","T","a","e","h","i","i","s","s","s","t","t")</pre>
=={{header| ZX Spectrum Basic}}==
|