Difference between revisions of "Bubble sort/fr"
From Lazarus wiki
Jump to navigationJump to search (Created page with "{{Bubble sort}} Le tri à bulle est un algorithme de tri simple. == Propriétés == * Très lent * Adapté seulement pour trier des données en petite quantité * Rapide s...") |
m (Fixed syntax highlighting) |
||
Line 11: | Line 11: | ||
== Unité UBubbleSort == | == Unité UBubbleSort == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="pascal"> |
unit UBubbleSort; | unit UBubbleSort; | ||
Line 59: | Line 59: | ||
== Exemple d'emploi == | == Exemple d'emploi == | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="pascal"> |
uses | uses | ||
UBubbleSort | UBubbleSort |
Latest revision as of 07:26, 10 February 2020
│
English (en) │
suomi (fi) │
français (fr) │
Le tri à bulle est un algorithme de tri simple.
Propriétés
- Très lent
- Adapté seulement pour trier des données en petite quantité
- Rapide seulement quand le tableau est presque trié
Unité UBubbleSort
unit UBubbleSort;
interface
type
// data type
TItemBubbleSort=integer;
procedure BubbleSort( var a: array of TItemBubbleSort );
implementation
procedure swap( var a, b:TItemBubbleSort );
var
temp : TItemBubbleSort;
begin
temp := a;
a := b;
b := temp;
end;
procedure BubbleSort( var a: array of TItemBubbleSort );
var
n, newn, i:integer;
begin
n := high( a );
repeat
newn := 0;
for i := 1 to n do
begin
if a[ i - 1 ] > a[ i ] then
begin
swap( a[ i - 1 ], a[ i ]);
newn := i ;
end;
end ;
n := newn;
until n = 0;
end;
end.
Exemple d'emploi
uses
UBubbleSort
...
var
a: array[0..100] of integer;
begin
...
BubbleSort(a);
...