Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
m
Whitespace removal
(Undo revision 65088 by 66.194.217.221 (Talk) Vandalism) |
m (Whitespace removal) |
||
Line 44:
{{works with|GCC|4.1.2}}
<lang ada>
end loop;▼
exit when Finished;▼
end loop;
end Bubble_Sort;▼
-- Example of usage:▼
with Ada.Text_IO; use Ada.Text_IO;▼
with Bubble_Sort;▼
procedure Main is▼
type Arr is array (Positive range <>) of Integer;▼
Bubble_Sort▼
Index => Positive,▼
A : Arr := (1, 3, 256, 0, 3, 4, -1);▼
Arr => Arr);
begin▼
Sort (A);▼
Put (Integer'Image (A (J)));▼
for J
New_Line;▼
end
end Main;</lang>▼
=={{header|ALGOL 68}}==
<lang algol68>MODE DATA = INT;
PROC swap = (REF[]DATA slice)VOID:
(
Line 189 ⟶ 188:
=={{header|BASIC}}==
{{works with|QuickBasic|4.5}}
{{trans|Java}}▼
▲{{trans|Java}}
Assume numbers are in a DIM of size "size" called "nums".
<lang qbasic>DO
Line 344 ⟶ 343:
=={{header|Common Lisp}}==
Bubble sort an sequence in-place, using the < operator for comparison if no comaprison function is provided
<lang lisp>(defun bubble-sort (sequence &optional (compare #'<))
"sort a sequence (array or list) with an optional comparison function (cl:< is the default)"
Line 616 ⟶ 614:
=={{header|Lisaac}}==
<lang Lisaac>Section Header
+ name := BUBBLE_SORT;
Line 659 ⟶ 656:
};
}.do_while {!sorted};
);</lang>
▲</lang>
=={{header|Lucid}}==
Line 682 ⟶ 678:
=={{header|M4}}==
<lang M4>divert(-1)
define(`randSeed',141592653)
Line 727 ⟶ 722:
show(`a')
bubblesort(`a')
show(`a')</lang>
Output:
<pre>17 63 80 55 90 88 25 9 71 38▼
▲17 63 80 55 90 88 25 9 71 38
9 17 25 38 55 63 71 80 88 90</pre>
=={{header|Mathematica}}==
Line 980 ⟶ 972:
{{eff note|Ruby|Array.sort!}}This example adds the bubblesort! method to the Array object. Below are two different methods that show four different iterating constructs in ruby.
<lang ruby>
def bubblesort2!
▲ ary = [3, 78, 4, 23, 6, 8, 6]
▲ ary.bubblesort1!
▲ p ary
▲ # => [3, 4, 6, 6, 8, 23, 78]</lang>
=={{header|Scheme}}==
Line 1,026 ⟶ 1,016:
This solution iteratively finds the fixed point of sort-step. A comparison function must be passed to bubblesort. Example usages:
<lang scheme>
Here is a recursive bubble sort which sorts list 'l' using the comparator 'f':
Line 1,045 ⟶ 1,035:
=={{header|Seed7}}==
<lang seed7>const proc: bubbleSort (inout array integer: arr) is func
=={{header|Smalltalk}}==
Line 1,179 ⟶ 1,169:
=={{header|Ursala}}==
The bubblesort function is parameterized by a relational predicate.
<lang Ursala>#import nat
bubblesort "p" = @iNX ^=T ^llPrEZryPrzPlrPCXlQ/~& @l ~&aitB^?\~&a "p"?ahthPX/~&ahPfatPRC ~&ath2fahttPCPRC
Line 1,189 ⟶ 1,178:
output:
<pre><140,212,247,270,315,362,449,532,567,677></pre>
=={{header|Visual Basic .NET}}==
|