all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,6 @@
|
|||
generic
|
||||
type Element_Type is private;
|
||||
type Index is (<>);
|
||||
type Collection is array(Index) of Element_Type;
|
||||
with function "<=" (Left, Right : Element_Type) return Boolean is <>;
|
||||
procedure Gnome_Sort(Item : in out Collection);
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
procedure Gnome_Sort(Item : in out Collection) is
|
||||
procedure Swap(Left, Right : in out Element_Type) is
|
||||
Temp : Element_Type := Left;
|
||||
begin
|
||||
Left := Right;
|
||||
Right := Temp;
|
||||
end Swap;
|
||||
|
||||
I : Integer := Index'Pos(Index'Succ(Index'First));
|
||||
J : Integer := I + 1;
|
||||
begin
|
||||
while I <= Index'Pos(Index'Last) loop
|
||||
if Item(Index'Val(I - 1)) <= Item(Index'Val(I)) then
|
||||
I := J;
|
||||
J := J + 1;
|
||||
else
|
||||
Swap(Item(Index'Val(I - 1)), Item(Index'Val(I)));
|
||||
I := I - 1;
|
||||
if I = Index'Pos(Index'First) then
|
||||
I := J;
|
||||
J := J + 1;
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
end Gnome_Sort;
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
with Gnome_Sort;
|
||||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
|
||||
procedure Gnome_Sort_Test is
|
||||
type Index is range 0..9;
|
||||
type Buf is array(Index) of Integer;
|
||||
procedure Sort is new Gnome_Sort(Integer, Index, Buf);
|
||||
A : Buf := (900, 700, 800, 600, 400, 500, 200, 100, 300, 0);
|
||||
begin
|
||||
for I in A'range loop
|
||||
Put(Integer'Image(A(I)));
|
||||
end loop;
|
||||
New_Line;
|
||||
Sort(A);
|
||||
for I in A'range loop
|
||||
Put(Integer'Image(A(I)));
|
||||
end loop;
|
||||
New_Line;
|
||||
end Gnome_Sort_Test;
|
||||
Loading…
Add table
Add a link
Reference in a new issue