with Ada.Text_IO; use Ada.Text_IO;

   with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;

   with Ada.Strings.Fixed;

 ¬¹¹¹¹¹¹¹¹¹

Þßàprocedure Test_Tri is

 ªË¹¹¹¹¹¹¹¹

  § ¬¹ÈÈÈÈÈÈÈÈ

  §Ûâãgeneric

  § § type Échanger_Type is private;

  § § procedure Échanger ( Premier, Second : in out Échanger_Type);

  § ªÈÈÈÈÈÈÈÈÈ

  §pragma Inline (Échanger);

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàprocedure Échanger ( Premier, Second : in out Échanger_Type) is

  § ªË¹¹¹¹¹¹¹¹

  §  § í Tmp : Échanger_Type;

  §  §begin

  §  ¨¹¹ Tmp := Premier;

  §  ¨¹¹ Premier := Second;

  §  ¨¹¹ Second := Tmp;

  §  ©end Échanger;

  §

  § ¬¹ÈÈÈÈÈÈÈÈ

  §Ûâãgeneric

  § § type Élément      is private;

  § § type Index         is ( <> );

  § § type Vecteur     is array (Index range <>) of Élément;

  § § with function ">" (A, B : in Élément) return Boolean is <>;

  § § procedure Tri_Par_Insertion ( A : in out Vecteur);

  § ªÈÈÈÈÈÈÈÈÈ

  §pragma Inline (Tri_Par_Insertion);

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàprocedure Tri_Par_Insertion ( A : in out Vecteur) is

  § ªË¹¹¹¹¹¹¹¹

  §  § í I, J      : Index range A'RANGE;

  §  § í T      : Élément;      -- type de la variable temporaire est générique

  §  § í L      : Index range A'RANGE:= A'FIRST;

  §  § í U      : Index range A'RANGE:= A'LAST;

  §  §begin

  §  ¨¹¹ I := L;

  §  ¨¹¹±while I /=  U  loop

  §  §  7¹¹ T := A(Index'Succ(I));

  §  §  7¹¹ J := Index'Succ(I);

  §  §  7¹¹±while J /= L and then A(Index'Pred(j))  > T loop

  §  §  5  7¹¹ A(J) := A(Index'Pred(J));

  §  §  5  7¹¹ J     := Index'Pred(J);

  §  §  5  °end loop;

  §  §  7¹¹ A (J) := T;

  §  §  7¹¹ I := Index'Succ(I);

  §  §  °end loop;

  §  ©end Tri_Par_Insertion;

  §

  § ¬¹ÈÈÈÈÈÈÈÈ

  §Ûâãgeneric

  § § type Élément      is private;

  § § type Index         is ( <> );

  § § type Vecteur     is array (Index range <>) of Élément;

  § § with procedure Échanger ( A, B : in out Élément );

  § § with function ">" (A, B : in Élément) return Boolean is <>;

  § § procedure Tri_En_Bulle ( X : in out Vecteur);

  § ªÈÈÈÈÈÈÈÈÈ

  §pragma Inline (Tri_En_Bulle);

  §

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàprocedure Tri_En_Bulle ( X : in out Vecteur) is

  § ªË¹¹¹¹¹¹¹¹

  §  § í Last : Index := X'Last;

  §  §begin

  §  ¨¹¹±for I in reverse X'First .. Index'Pred(Last) loop

  §  §  7¹¹±for J in Index'First .. I loop

  §  §  5  7¹³´if  X(J) > X(Index'Succ(J))  then

  §  §  5  5 6¾¹¹ Échanger ( X(J), X(Index'Succ(J)));

  §  §  5  5 ¶ end if;      

  §  §  5  °end loop;

  §  §  °end loop;

  §  ©end Tri_En_Bulle;

  §

  § ¬¹ÈÈÈÈÈÈÈÈ

  §Ûâãgeneric

  § § type Élément      is private;

  § § type Index         is ( <> );

  § § type Vecteur     is array (Index range <>) of Élément;

  § § with function ">" (A, B : in Élément) return Boolean is <>;

  § § procedure Tri_En_Bulle2 ( X : in out Vecteur);

  § ªÈÈÈÈÈÈÈÈÈ

  §pragma Inline (Tri_En_Bulle2);

  §

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàprocedure Tri_En_Bulle2 ( X : in out Vecteur) is

  § ªË¹¹¹¹¹¹¹¹

  §  § í Last : Index := X'Last;

  §  § ¬¹¹¹¹¹¹¹¹¹

  §  §ÛÜÝprocedure Échanger ( A, B : in out Élément );

  §  § ª¹¹¹¹¹¹¹¹¹

  §  §pragma Inline ( Échanger );

  §  § ¬¹¹¹¹¹¹¹¹¹

  §  §Þßàprocedure Échanger ( A, B : in out Élément ) is

  §  § ªË¹¹¹¹¹¹¹¹

  §  §  § í Temp : Élément;

  §  §  §begin

  §  §  ¨¹¹ Temp := A;

  §  §  ¨¹¹ A := B;

  §  §  ¨¹¹ B := Temp;

  §  §  ©end Échanger;

  §  §begin

  §  ¨¹¹±for I in reverse X'First .. Index'Pred(Index(X'Last)) loop

  §  §  7¹¹±for J in Index'First .. I loop

  §  §  5  7¹³´if  X(J) > X(Index'Succ(J))  then

  §  §  5  5 6¾¹¹ Échanger ( X(J), X(Index'Succ(J)));

  §  §  5  5 ¶ end if;

  §  §  5  °end loop;

  §  §  °end loop;

  §  ©end Tri_En_Bulle2;

  §

  § ï type Couleur_Type is ( Rouge, Jaune, Vert, Bleu, Magenta, NavajoRed, PapayaWhip);

  § ï type Tableau_Couleur_Type is array ( Couleur_Type range <> ) of Couleur_Type;

  § í A : Tableau_Couleur_Type := ( Magenta, Vert, NavajoRed,Jaune, Rouge, Bleu, PapayaWhip);

  § ¬¹¹¹¹¹¹¹¹¹

  §ÛÜÝprocedure Échanger_Couleur is new Échanger ( Couleur_Type );

  § ª¹¹¹¹¹¹¹¹¹

  § ¬¹¹¹¹¹¹¹¹¹

  §ÛÜÝprocedure Tri_Couleur is new Tri_En_Bulle (      Élément => Couleur_Type,

Index      => Couleur_Type,

  § §                                                                                             Vecteur => Tableau_Couleur_Type,

Échanger      => Échanger_Couleur);

  § ª¹¹¹¹¹¹¹¹¹

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàprocedure Put (A : in Tableau_Couleur_Type) is

  § ªË¹¹¹¹¹¹¹¹

  §  §

  §  §begin

  §  ¨¹¹±for i in A'Range loop

  §  §  7¹¹ Put_Line ( Couleur_Type'Image(A(i)));

  §  §  °end loop;

  §  ©end Put;

  §

  § ï type Tableau_Caractère_Type is array ( Integer range <> ) of Character;

  § í B : Tableau_Caractère_Type := ('z', 'B', 'r', 'e', 'p','A', '>', '=', NUL,

  §                                  'C', 'Q','à', 'é', 'è', 's', ')', '(', '0',

  §                                  ''' ,'k', ACK);

  § ¬¹¹¹¹¹¹¹¹¹

  §ÛÜÝprocedure Tri_Caractère is new Tri_En_Bulle2 ( Character, Integer, Tableau_Caractère_Type);

  § ª¹¹¹¹¹¹¹¹¹

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàprocedure Put (A : in Tableau_Caractère_Type) is

  § ªË¹¹¹¹¹¹¹¹

  §  § ¡¥¥¥¥¥¥¥¥¥

  §  §ØÓìpackage Int_IO is new Ada.Text_IO.Integer_IO ( Integer );

  §  § £¦¦¦¦¦¦¦¦¦

  §  §   use Int_IO;

  §  §begin

  §  ¨¹¹±for i in A'Range loop

  §  §  7¹¹ Set_Col ( 2 ); Put ( Character'Pos(A(i)), 5, 16);      -- Code hexadécimal

  §  §  7¹¹ Set_Col ( 10); Put ( A ( i));                        -- le caractère

  §  §  7¹¹ Set_Col(20); Put_Line ( Character'Image(A(i)));         -- le litéral énumératif

  §  §  °end loop;

  §  ©end Put;

  §

  § ï type Étudiant_Type is

  §      record

  §         Matricule : String (1 .. 6 );

  §         Nom : String ( 1 .. 20 );

  §         Prénom : String ( 1 .. 15);

  §      end record;

  § ï type Tableau_Étudiant_Type is array ( Integer range <> ) of Étudiant_Type;

  § í Étudiants : Tableau_Étudiant_Type := (

  §                                          ("123456", "Bleau               ", "Jos            "),

  §                                          ("163234", "Larivée             ", "Pierre         "),

  §                                          ("043562", "Doe                 ", "John           "));

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàfunction  Comparer_Matricule ( A, B : in Étudiant_Type ) return Boolean is

  § ªË¹¹¹¹¹¹¹¹

  §  §begin

  §Â¹Ä¹¹ return A.Matricule > B.Matricule;

  §  ©end Comparer_Matricule;

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàfunction  Comparer_Nom ( A, B : in Étudiant_Type ) return Boolean is

  § ªË¹¹¹¹¹¹¹¹

  §  §

  §  §begin

  §Â¹Ä¹¹ return A.Nom > B.Nom;

  §  ©end Comparer_Nom;

  § ¬¹¹¹¹¹¹¹¹¹

  §Þßàprocedure Put ( A : in Tableau_Étudiant_Type ) is

  § ªË¹¹¹¹¹¹¹¹

  §  §   use Ada.Strings.Fixed;

  §  §   use Ada.Strings;

  §  §begin

  §  ¨¹¹±for i in A'Range loop

  §  §  7¹¹ Set_Col ( 5 ); Put ( A(i).Matricule );      -- le matricule

  §  §  7¹¹ Set_Col ( 14); Put ( Trim (A(i).Nom, Right));     -- le nom, les espaces à droite enlevés,

  §  §  7¹¹ Ada.Text_IO.Put ( ", "); Put ( Trim (A(i).Prénom, Right));      -- suivi d'une , et le prénom

  §  §  7¹¹ New_Line;

  §  §  °end loop;

  §  ©end Put;

  § ¬¹¹¹¹¹¹¹¹¹

  §ÛÜÝprocedure Échanger_Étudiant is new Échanger ( Étudiant_Type );

  § ª¹¹¹¹¹¹¹¹¹

  § ¬¹¹¹¹¹¹¹¹¹

  §ÛÜÝprocedure Tri_Par_Matricule is new Tri_En_Bulle (      Élément => Étudiant_Type,

  § §                                                                                                       Index    => Integer,

  § §                                                                                                       Vecteur => Tableau_Étudiant_Type,

  § §                                                                                                       Échanger      => Échanger_Étudiant,

  § §                                                                                                       ">"      => Comparer_Matricule);

  § ª¹¹¹¹¹¹¹¹¹

  § ¬¹¹¹¹¹¹¹¹¹

  §ÛÜÝprocedure Tri_Alphabétique is new Tri_En_Bulle (      Élément => Étudiant_Type,

  § §                                                                                                       Index    => Integer,

  § §                                                                                                       Vecteur => Tableau_Étudiant_Type,

  § §                                                                                                       Échanger      => Échanger_Étudiant,

  § §                                                                                                       ">"      => Comparer_Nom);

  § ª¹¹¹¹¹¹¹¹¹

  §

  §begin

  ¨¹¹ Tri_Couleur ( A );

  ¨¹¹ Put_Line ( " Le tableau de couleur trié" );

  ¨¹¹ Put ( A );

  ¨¹¹ Tri_Caractère ( B );

  ¨¹¹ Put_Line ( " Le tableau de caractère trié " );

  ¨¹¹ Put ( B );

  ¨¹¹ Put_Line ( " Le tableau des étudiants par matricule");

  ¨¹¹ Tri_Par_Matricule ( Étudiants );

  ¨¹¹ Put (Étudiants);

  ¨¹¹ Put_Line ( " Le tableau des étudiants par ordre aphabétique");

  ¨¹¹ Tri_Alphabétique ( Étudiants );

  ¨¹¹ Put (Étudiants);

  ©end Test_Tri;