Sign in Join
Wiki copytemporary

Bubble sort/fr

English · Français · Suomi

Le tri à bulle est un algorithme de tri simple.

Propriétés

Unité UBubbleSort

pascal
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

pascal
uses
  UBubbleSort
  ...

var
  a: array[0..100] of integer; 
begin
  ...
  BubbleSort(a);
  ...

Voir aussi


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.

Revision 3, last changed by WikiArchive .

Edited on wiki.freepascal.org by 2 people, 2016–2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
E-ricCreated page
TrevFixed syntax highlighting (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.