Logo

Programming-Idioms

History of Idiom 100 > diff from v30 to v31

Edit summary for version 31 by programming-idioms.org:
[Ada] Reduced indentation

Version 30

2016-12-11, 20:37:02

Version 31

2016-12-11, 20:38:44

Idiom #100 Sort by a comparator

Sort elements of array-like collection items, using a comparator c.

Idiom #100 Sort by a comparator

Sort elements of array-like collection items, using a comparator c.

Imports
with Ada.Containers.Vectors;
use Ada.Containers;
Imports
with Ada.Containers.Vectors;
use Ada.Containers;
Code
      type Integer_Comparator is not null access function (Left, Right : Integer) return Boolean;
      
      package Integer_Vectors is new Vectors (Positive, Integer);
      use Integer_Vectors;
      
      procedure Sort_Using_Comparator (V : in out Vector; C : Integer_Comparator) is
         package Vector_Sorting is new Generic_Sorting (C.all);
         use Vector_Sorting;
         
      begin
         Sort (V);
      end Sort_Using_Comparator;
Code
type Integer_Comparator is not null access function (Left, Right : Integer) return Boolean;
      
package Integer_Vectors is new Vectors (Positive, Integer);
use Integer_Vectors;
      
procedure Sort_Using_Comparator (V : in out Vector; C : Integer_Comparator) is
   package Vector_Sorting is new Generic_Sorting (C.all);
   use Vector_Sorting;
         
begin
   Sort (V);
end Sort_Using_Comparator;