Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m ({{out}}) |
PatGarrett (talk | contribs) (Add Scilab section) |
||
Line 3,288:
} while(hasChanged)
}</lang>
=={{header|Scilab}}==
<lang>function b=BubbleSort(a)
n=length(a)
swapped=%T
while swapped
swapped=%F
for i=1:1:n-1
if a(i)>a(i+1) then
temp=a(i)
a(i)=a(i+1)
a(i+1)=temp
swapped=%T
end
end
end
b=a
endfunction BubbleSort</lang>
{{out}}
<pre style="height:20ex">-->y=[5 4 3 2 1]
y =
5. 4. 3. 2. 1.
-->x=BubbleSort(a)
x =
1. 2. 3. 4. 5. </pre>
=={{header|Scheme}}==
|