« Implémentation d'algorithmes classiques/Algorithmes de tri/Tri par sélection » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
DannyS712 (discussion | contributions)
m <source> -> <syntaxhighlight> (phab:T237267)
Ligne 1 :
== [[Programmation C|C]] ==
<sourcesyntaxhighlight lang=c>
void selection(int *t, int taille)
{
Ligne 16 :
}
}
</syntaxhighlight>
</source>
 
== [[Programmation C++|C++]] ==
Ligne 22 :
=== Old C++ (before 2011) ===
 
<sourcesyntaxhighlight lang=cpp>
void triSelection(int tab[], int const taille)
{
Ligne 43 :
}
}
</syntaxhighlight>
</source>
 
=== Modern C++ ( use -std=c++11 to compile ) ===
 
<sourcesyntaxhighlight lang=cpp>
template< typename T >
void triSelection( T& tab )
Ligne 69 :
}
}
</syntaxhighlight>
</source>
 
Note that this example can not be used with classic arrays ( "int tab[50];" ) but it can be used with any container, including std::array, which is a classic array in the final binary. The advantage of std::array being that you can retrieve it's size without the need of global constants ( no need to do things like "#define SIZE 50" or "const size_t SIZE = 50;" as in C, and so less dangers of error when you do changes ).
Ligne 75 :
== [[Objective Caml|Caml]] ==
Tri de vecteurs en [[w:Caml_Light|Caml Light]], en ordre décroissant :
<sourcesyntaxhighlight lang=ocaml>
let tri_select t =
let n = vect_length t and m = ref(0) and i = ref(0) in
Ligne 91 :
done;
t;;
</syntaxhighlight>
</source>
 
== [[Programmation Haskell|Haskell]] ==
<sourcesyntaxhighlight lang=Haskell>
selTri :: Ord a 26 => [a] -> [a]
remFirstOcc :: Ord a => a->[a] -> [a]
Ligne 105 :
| (x == n) = xs
| otherwise = x:(remFirstOcc n xs)
</syntaxhighlight>
</source>
 
== [[Programmation Java|Java]] ou [[Programmation C sharp|C#]] ==
<sourcesyntaxhighlight lang=java>
public void sortBySelection(int[] t, int sizeOfTheCollection) {
 
Ligne 127 :
 
}
</syntaxhighlight>
</source>
 
== [[Programmation Javascript|Javascript]] ==
T est un tableau de nombres dont le premier indice est 0, et n est un entier tel que l'on souhaite trier T[0..n-1].
<sourcesyntaxhighlight lang=javascript>
function executer_tri_par_selection (T, n) {
if (T.length < 2) return T;
Ligne 149 :
return T;
}
</syntaxhighlight>
</source>
 
== [[Programmation Pascal|Pascal]] ==
<sourcesyntaxhighlight lang=pascal>
procedure TriSelection(n : integer ; var t : tab);
var i, j, min, tmp : integer;
Ligne 169 :
end;
end;
</syntaxhighlight>
</source>
 
== [[Programmation PHP|PHP]] ==
<sourcesyntaxhighlight lang=php>
function triSelection(&$arrayOf)
{
Ligne 196 :
}
}
</syntaxhighlight>
</source>
 
== [[Programmation Python|Python]] ==
<sourcesyntaxhighlight lang=Python>
import random
 
Ligne 215 :
un_tableau[k] = un_tableau[min]
un_tableau[min] = number
</syntaxhighlight>
</source>
 
<small>Tout ou partie de cette page est issue de l'article Wikipédia « [[w:Tri par sélection|Tri par sélection]] » dans sa [{{fullurl:w:Tri_par_sélection|oldid=52309066}} version du 22/04/2010].</small>