Sign in Join
Wiki copytemporary

Bubble sort/fr: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Bubble sort/fr

OldNewLine
1+Le tri à bulle est un algorithme de tri simple.
2+
3+## Propriétés
4+
5+- Très lent
6+- Adapté seulement pour trier des données en petite quantité
7+- Rapide seulement quand le tableau est presque trié
8+
9+## Unité UBubbleSort
10+
11+``` pascal
12+unit UBubbleSort;
13+
14+interface
15+
16+type
17+ // data type
18+ TItemBubbleSort=integer;
19+
20+procedure BubbleSort( var a: array of TItemBubbleSort );
21+
22+implementation
23+
24+procedure swap( var a, b:TItemBubbleSort );
25+var
26+ temp : TItemBubbleSort;
27+begin
28+ temp := a;
29+ a := b;
30+ b := temp;
31+end;
32+
33+procedure BubbleSort( var a: array of TItemBubbleSort );
34+var
35+ n, newn, i:integer;
36+begin
37+ n := high( a );
38+ repeat
39+ newn := 0;
40+ for i := 1 to n do
41+ begin
42+ if a[ i - 1 ] > a[ i ] then
43+ begin
44+ swap( a[ i - 1 ], a[ i ]);
45+ newn := i ;
46+ end;
47+ end ;
48+ n := newn;
49+ until n = 0;
50+end;
51+
52+end.
53+```
54+
55+## Exemple d'emploi
56+
57+``` pascal
58+uses
59+ UBubbleSort
60+ ...
61+
62+var
63+ a: array[0..100] of integer;
64+begin
65+ ...
66+ BubbleSort(a);
67+ ...
68+```
69+
70+## Voir aussi
71+
72+- \[<https://www.youtube.com/watch?v=DXO-nqATduU>\| COMP1 Réviser et Apprendre : Tri à bulle\]
73+
74+---
75+*From the Free Pascal wiki, page "Bubble sort/fr", as it stood on 2020-02-10 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history