svn add vector.ad*

git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@209563 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
lfainsin 2020-12-19 15:12:22 +00:00
parent 1d9e35627e
commit 394360c5df
2 changed files with 93 additions and 0 deletions

65
src/vector.adb Normal file
View file

@ -0,0 +1,65 @@
package body vector is
procedure initialize(vec: in out T_Vecteur) is
begin
for i in 0..N-1 loop
vec(i) := 1.0/T_Element(N);
end loop;
end initialize;
procedure initialize(vec: in out T_Vecteur_Index) is
begin
for i in 0..N-1 loop
vec(i) := i;
end loop;
end initialize;
procedure put(vec: in T_Vecteur) is
begin
for i in 0..N-1 loop
put(vec(i)); new_line;
end loop;
end put;
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur) is
begin
for i in 0..N-1 loop
put(file, vec(i), 1);
new_line(file);
end loop;
end put;
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Index) is
begin
for i in 0..N-1 loop
put(file, vec(i), 1);
new_line(file);
end loop;
end put;
procedure sort_with_index_desc(vec: in out T_Vecteur; vec_index: out T_Vecteur_Index) is
tmp_Element: T_Element;
tmp_Natural: Natural;
max: Natural;
begin
for i in 0..N-2 loop
max := i;
for j in i+1..N-1 loop
if vec(max) < vec(j) then
max := j;
end if;
end loop;
if max /= i then
tmp_Element := vec(i);
vec(i) := vec(max);
vec(max) := tmp_Element;
tmp_Natural := vec_index(i);
vec_index(i) := vec_index(max);
vec_index(max) := tmp_Natural;
end if;
end loop;
end sort_with_index_desc;
end vector;

28
src/vector.ads Normal file
View file

@ -0,0 +1,28 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
generic
type T_Element is digits <>;
N: Positive;
package Vector is
type T_Vecteur is array (0..N-1) of T_Element;
type T_Vecteur_Index is array (0..N-1) of Natural;
-- on permet l'affichage direct des T_Element
package Text_T_Element is
new Ada.Text_IO.Float_IO(Num => T_Element);
use Text_T_Element;
procedure initialize(vec: in out T_Vecteur);
procedure initialize(vec: in out T_Vecteur_Index);
procedure put(vec: in T_Vecteur);
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur);
procedure put(file: in out Ada.Text_IO.File_Type; vec: in T_Vecteur_Index);
procedure sort_with_index_desc(vec: in out T_Vecteur; vec_index: out T_Vecteur_Index);
end Vector;