Bubble sort/fr: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 1 | + | Le tri à bulle est un algorithme de tri simple. | |
| 2 | 2 | ||
| 3 | + | ## Contents | |
| 4 | + | ||
| 5 | + | * 1 Propriétés | |
| 6 | + | * 2 Unité UBubbleSort | |
| 7 | + | * 3 Exemple d'emploi | |
| 8 | + | * 4 Voir aussi | |
| 9 | + | ||
| 3 | 10 | ## Propriétés | |
| 4 | 11 | ||
| 5 | - | ||
| 6 | - | ||
| 7 | - | ||
| 12 | + | * Très lent | |
| 13 | + | * Adapté seulement pour trier des données en petite quantité | |
| 14 | + | * Rapide seulement quand le tableau est presque trié | |
| 8 | 15 | ||
| 9 | 16 | ## Unité UBubbleSort | |
| 10 | - | ||
| 11 | - | ||
| 17 | + | ``` | |
| 12 | 18 | unit UBubbleSort; | |
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 19 | + | ||
| 20 | + | interface | |
| 21 | + | ||
| 22 | + | type | |
| 23 | + | // data type | |
| 24 | + | TItemBubbleSort=integer; | |
| 25 | + | ||
| 26 | + | procedure BubbleSort( var a: array of TItemBubbleSort ); | |
| 27 | + | ||
| 28 | + | ||
| 29 | + | implementation | |
| 30 | + | ||
| 31 | + | procedure swap( var a, b:TItemBubbleSort ); | |
| 32 | + | var | |
| 33 | + | temp : TItemBubbleSort; | |
| 34 | + | begin | |
| 35 | + | temp := a; | |
| 36 | + | a := b; | |
| 37 | + | b := temp; | |
| 38 | + | end; | |
| 39 | + | ||
| 40 | + | ||
| 41 | + | procedure BubbleSort( var a: array of TItemBubbleSort ); | |
| 42 | + | var | |
| 43 | + | n, newn, i:integer; | |
| 44 | + | begin | |
| 45 | + | n := high( a ); | |
| 46 | + | repeat | |
| 47 | + | newn := 0; | |
| 48 | + | for i := 1 to n do | |
| 43 | 49 | begin | |
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 50 | + | if a[ i - 1 ] > a[ i ] then | |
| 51 | + | begin | |
| 52 | + | swap( a[ i - 1 ], a[ i ]); | |
| 53 | + | newn := i ; | |
| 54 | + | end; | |
| 55 | + | end ; | |
| 56 | + | n := newn; | |
| 57 | + | until n = 0; | |
| 58 | + | end; | |
| 59 | + | ||
| 60 | + | end. | |
| 53 | 61 | ``` | |
| 54 | 62 | ||
| 55 | 63 | ## Exemple d'emploi | |
| 56 | - | ||
| 57 | - | ||
| 64 | + | ``` | |
| 58 | 65 | uses | |
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - | ||
| 66 | + | UBubbleSort | |
| 67 | + | ... | |
| 68 | + | ||
| 69 | + | var | |
| 70 | + | a: array[0..100] of integer; | |
| 71 | + | begin | |
| 72 | + | ... | |
| 73 | + | BubbleSort(a); | |
| 74 | + | ... | |
| 68 | 75 | ``` | |
| 69 | 76 | ||
| 70 | 77 | ## Voir aussi | |
| 71 | 78 | ||
| 72 | - | ||
| 79 | + | * [COMP1 Réviser et Apprendre : Tri à bulle](<https://www.youtube.com/watch?v=DXO-nqATduU%7C>) | |
| 73 | 80 | ||
| 74 | 81 | --- | |
| 75 | - | ||
| 82 | + | *From the Free Pascal wiki, page "Bubble sort/fr", as the Internet Archive kept it on 2023-03-30. 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).* |
