Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
(→{{header|RapidQ}}: Added a solution.) |
Basicgames (talk | contribs) |
||
Line 1,400: | Line 1,400: | ||
<pre>unsort -7 3 -4 -6 4 -1 -2 2 7 0 5 1 -3 -5 6 |
<pre>unsort -7 3 -4 -6 4 -1 -2 2 7 0 5 1 -3 -5 6 |
||
sort -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7</pre> |
sort -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7</pre> |
||
=={{header|FTCBASIC}}== |
|||
<syntaxhighlight lang="basic">define sorting = 0, index = 0, size = 10, temp1 = 0, temp2 = 0 |
|||
dim list[10] |
|||
gosub fill |
|||
gosub sort |
|||
gosub output |
|||
pause |
|||
end |
|||
sub fill |
|||
0 index |
|||
do |
|||
print "Enter value #" \ |
|||
print index \ |
|||
print ": " \ |
|||
input @list[index] |
|||
+1 index |
|||
loop index < size |
|||
return |
|||
sub sort |
|||
do |
|||
0 sorting |
|||
0 index |
|||
do |
|||
let temp1 = index + 1 |
|||
if @list[index] > @list[temp1] then |
|||
let temp2 = @list[index] |
|||
let @list[index] = @list[temp1] |
|||
let @list[temp1] = temp2 |
|||
let sorting = 1 |
|||
endif |
|||
+1 index |
|||
loop index < size - 1 |
|||
loop sorting = 1 |
|||
return |
|||
sub output |
|||
0 index |
|||
do |
|||
print "#" \ |
|||
print index \ |
|||
print ": " \ |
|||
print @list[index] |
|||
+1 index |
|||
loop index < size |
|||
return</syntaxhighlight> |
|||
==={{header|FutureBasic}}=== |
==={{header|FutureBasic}}=== |