Реализации алгоритмов/Сортировка/Пузырьком: различия между версиями

Содержимое удалено Содержимое добавлено
м <source> -> <syntaxhighlight> (phab:T237267)
Строка 3:
 
=== Синтаксис Intel ===
<sourcesyntaxhighlight lang="asm">
mov bx, offset array
mov cx, n
Строка 21:
exit_for_j:
loop for_i
</syntaxhighlight>
</source>
 
=== Синтаксис AT&T (GNU) ===
<sourcesyntaxhighlight lang="asm">
.text
# void bubble_sort (unsigned *array, unsigned length);
Строка 51:
exit:
ret
</syntaxhighlight>
</source>
 
== C ==
<sourcesyntaxhighlight lang="c">
#define SWAP(A, B) { int t = A; A = B; B = t; }
 
Строка 71:
} while (n);
}
</syntaxhighlight>
</source>
 
== C++ ==
=== С использованием Template ===
<sourcesyntaxhighlight lang="cpp">
#include <algorithm>
template< typename Iterator >
Строка 85:
std::iter_swap( i, i + 1 );
}
</syntaxhighlight>
</source>
 
=== Без использования Template ===
<sourcesyntaxhighlight lang="cpp">
void bubble(int* a, int n)
{
Строка 103:
}
 
</syntaxhighlight>
</source>
 
== C++ ==
<sourcesyntaxhighlight lang="cpp">
 
#include <cstddef>
Строка 125:
}
}
</syntaxhighlight>
</source>
 
== C# ==
<sourcesyntaxhighlight lang="csharp">
static int[] BubbleSort(int[] mas)
{
Строка 146:
return mas;
}
</syntaxhighlight>
</source>
 
== Delphi ==
Сортировка одномерного динамического целочисленного массива:
<sourcesyntaxhighlight lang="pascal">
 
type
Строка 172:
until n=0;
end;
</syntaxhighlight>
</source>
 
== D ==
<sourcesyntaxhighlight lang="d">
void bubbleSort(alias op, T)(T[] inArray) {
foreach (i, ref a; inArray) {
Строка 187:
}
}
</syntaxhighlight>
</source>
 
== Fortran ==
<sourcesyntaxhighlight lang="fortran">
do i=n-1,1,-1
do j=1,i
Строка 200:
end do
end do
</syntaxhighlight>
</source>
 
== Java ==
<sourcesyntaxhighlight lang="java">
public int[] Sort(int[] array) {
int i = 0;
Строка 224:
return array;
}
</syntaxhighlight>
</source>
 
== Perl ==
<sourcesyntaxhighlight lang="perl">
for ( @out ) {
for ( 0..$#out-1 ) {
Строка 233:
}
}
</syntaxhighlight>
</source>
 
== Ruby ==
<sourcesyntaxhighlight lang="ruby">
arr = [5, 20, 3, 11, 1, 17, 3, 12, 8, 10]
swap = true
Строка 250:
puts arr.join(' ')
# output => 1 3 3 5 8 10 11 12 17 20
</syntaxhighlight>
</source>
 
== Python ==
<sourcesyntaxhighlight lang="python">
 
def bubble_sort(arr):
Строка 265:
assert bubble_sort([4, 3, 2, 1]) == [1, 2, 3, 4]
 
</syntaxhighlight>
</source>
 
== VBA ==
<sourcesyntaxhighlight lang="vb">
Sub Sort(Mus() As Long)
Dim i As Long, tmp As Long, t As Boolean
Строка 284:
Loop
End Sub
</syntaxhighlight>
</source>
 
== PHP ==
 
<sourcesyntaxhighlight lang="php">
for ($i = 0; $i < count($arr); $i++){
for ($j = $i + 1; $j < count($arr); $j++) {
Строка 298:
}
}
</syntaxhighlight>
</source>
 
Bubble Sort
Строка 314:
 
== JavaScript ==
<sourcesyntaxhighlight lang="javascript">
function sortBubble(data) {
var tmp;
Строка 333:
return data;
};
</syntaxhighlight>
</source>
 
== JavaScript ==
<sourcesyntaxhighlight lang="javascript">
function bubbleSort(seq:Number[]):Number[]{
 
Строка 354:
return sort;
}
</syntaxhighlight>
</source>
 
== Nemerle ==
<sourcesyntaxhighlight lang="csharp">
using System.Console;
using Nemerle.Collections;
Строка 369:
 
WriteLine($"Sorted list is a $(arr.ToList())");
</syntaxhighlight>
</source>
== [[:w:Turbo Basic|TurboBasic 1.1]]==
<sourcesyntaxhighlight lang="qbasic">
CLS
RANDOMIZE TIMER
Строка 430:
PRINT "ELAPSED TIME=";T1
</syntaxhighlight>
</source>
 
== [[:w:PL/SQL|PL/SQL]]==
<sourcesyntaxhighlight lang="plsql">
type sort_lst is table of integer;
--------------------------------------------------------
Строка 463:
end buble_sort;
 
</syntaxhighlight>
</source>
 
== Flex, ActionScript ==
<sourcesyntaxhighlight lang="ActionScript">
function bubbleSort(array:Vector.<Number>) {
for (var i:uint = 0; i < array.length; i++) {
Строка 478:
}
}
</syntaxhighlight>
</source>
 
== Ссылки ==