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

м
<source> -> <syntaxhighlight> (phab:T237267)
м (<source> -> <syntaxhighlight> (phab:T237267))
 
{{wikipedia|Сортировка выбором}}
== [[w:Си (язык программирования)|C]] ==
<sourcesyntaxhighlight lang="c">
for (int i = 0; i < size - 1; i++)
{
array[min_i] = temp;
}
</syntaxhighlight>
</source>
 
== [[w:C++|C++]] ==
<sourcesyntaxhighlight lang="cpp">
template <typename T, typename C = less< typename T::value_type> >
void select_sort( T f, T l, C c = C() )
}
 
</syntaxhighlight>
</source>
 
== [[w:C Sharp|C#]] ==
<sourcesyntaxhighlight lang="cpp">
public void SelectionSort(int[] arr)
{
}
}
</syntaxhighlight>
</source>
 
== [[w:Паскаль (язык программирования)|Паскаль]] ==
<sourcesyntaxhighlight lang="pascal">
for i := 1 to n - 1 do begin
min := i;
end;
end;
</syntaxhighlight>
</source>
 
== [[w:Компонентный Паскаль|Компонентный Паскаль]] ==
 
== [[w:D (язык программирования)|D]] ==
<sourcesyntaxhighlight lang="d">
void selectionSort(int[] array) {
int length = array.length;
}
}
</syntaxhighlight>
</source>
 
== [[w:VBA|VBA]] ==
<sourcesyntaxhighlight lang="vb">
Sub Sort(Mus() As Long)
Dim n As Long, i As Long, j As Long, min As Long
Next
End Sub
</syntaxhighlight>
</source>
 
== [[w:Java|Java]] ==
Итерационный алгоритм:
<sourcesyntaxhighlight lang='java'>
public static void selectionSort (int[] numbers){
int min, temp;
}
}
</syntaxhighlight>
</source>
 
Рекурсивный алгоритм:
<sourcesyntaxhighlight lang='java'>
public static int findMin(int[] array, int index){
int min = index - 1;
}
 
</syntaxhighlight>
</source>
 
== [[w:Ruby|Ruby]] ==
<sourcesyntaxhighlight lang="ruby">
a = [5, 20, 3, 11, 1, 17, 3, 12, 8, 10]
 
 
# output => 1 3 3 5 8 10 11 12 17 20
</syntaxhighlight>
</source>
 
== [[w:Python|Python]] ==
 
неустойчивая:
<sourcesyntaxhighlight lang='python'>
def swap(arr, i, j):
arr[i], arr[j] = arr[j], arr[i]
swap(arr, i - 1, max)
i -= 1
</syntaxhighlight>
</source>
 
устойчивая:
<sourcesyntaxhighlight lang='python'>
def select_sort_stable(arr):
if len(arr) == 0: return
arr[l] = arr[l - 1]
arr[j] = value
</syntaxhighlight>
</source>
 
== [[w:Ada|Ada]] ==
<sourcesyntaxhighlight lang="ada">
type arr is array(1..n) of integer;
i,j,t:integer;
end loop;
end sort;
</syntaxhighlight>
</source>
 
== [[w:PHP|PHP]] ==
<sourcesyntaxhighlight lang="php">
$size = count($arr);
 
$arr[$min] = $temp;
}
</syntaxhighlight>
</source>
 
==[[:w:TurboBasic 1.1|TurboBasic 1.1]]==
<big><sourcesyntaxhighlight lang="qbasic">
CLS
RANDOMIZE TIMER
PRINT "ELAPSED TIME=";T1
PRINT FRE(-1)
�</sourcesyntaxhighlight><big>
 
== [[w:PL/SQL|PL/SQL]] ==
<sourcesyntaxhighlight lang="plsql">
type sort_list is table of integer index by binary_integer;
-----------------------------------------------------------
end SORT_CHOISE;
</syntaxhighlight>
</source>
 
== Ссылки ==
583

правки