début implémentation quick_sort
git-svn-id: http://cregut.svn.enseeiht.fr/2020/1sn/pim/projets/GH-05@210321 e13453a9-b01f-0410-a051-f404c4f0c485
This commit is contained in:
parent
2123e2bf5d
commit
553a31bf39
|
@ -15,9 +15,12 @@ package body Google_Creux is
|
|||
procedure create_H(mat: in out T_Google; file: in out Ada.Text_IO.File_Type) is
|
||||
row, col: Natural;
|
||||
nb: Natural := 0;
|
||||
stdout: constant Ada.Text_IO.File_Type := Ada.Text_IO.Standard_Output;
|
||||
begin
|
||||
mat.rows(0) := 0;
|
||||
for i in 0..N-1 loop
|
||||
String'Write(Ada.Text_IO.Text_Streams.Stream(stdout),
|
||||
ASCII.CR & "ite:" & Integer'Image(i) & " /" & Integer'Image(N-1));
|
||||
reset(file, In_File);
|
||||
skip_line(file);
|
||||
for j in 0..N_links-1 loop
|
||||
|
|
|
@ -23,7 +23,6 @@ package Google_Creux is
|
|||
type T_Google is record
|
||||
cols: T_Cols;
|
||||
rows: T_Rows;
|
||||
offset: T_Element;
|
||||
end record;
|
||||
|
||||
function calcul(vec: T_Vecteur_Element; mat :T_Google; alpha: in T_Element) return T_Vecteur_Element;
|
||||
|
|
|
@ -180,9 +180,9 @@ procedure pageRank is
|
|||
"ite:" & Integer'Image(i) & " /" & Integer'Image(ite_max) & ASCII.CR);
|
||||
end loop; new_line;
|
||||
|
||||
new_line;
|
||||
put_line("final pi:");
|
||||
put(pi);
|
||||
-- new_line;
|
||||
-- put_line("final pi:");
|
||||
-- put(pi);
|
||||
|
||||
end algorithm_naif;
|
||||
|
||||
|
|
|
@ -79,4 +79,94 @@ package body vector is
|
|||
end loop;
|
||||
end sort_with_index_desc;
|
||||
|
||||
procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural) is
|
||||
pivot: Natural := a;
|
||||
i: Natural := a;
|
||||
tmp: T_Element;
|
||||
begin
|
||||
if b - a > 1 then
|
||||
for j in a..b loop
|
||||
if vec(j) <= vec(pivot) then
|
||||
i := i + 1;
|
||||
tmp := vec(i);
|
||||
vec(i) := vec(j);
|
||||
vec(j) := tmp;
|
||||
else
|
||||
null;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
tmp := vec(i);
|
||||
vec(i) := vec(pivot);
|
||||
vec(pivot) := tmp;
|
||||
|
||||
pivot := i;
|
||||
|
||||
put(vec); new_line;
|
||||
|
||||
if pivot - 1 > 0 then
|
||||
quicksort(vec, vec_index, a, pivot-1);
|
||||
elsif b - pivot - 1 > 0 then
|
||||
quicksort(vec, vec_index, pivot+1, b);
|
||||
else
|
||||
null;
|
||||
end if;
|
||||
else
|
||||
null;
|
||||
end if;
|
||||
end quicksort;
|
||||
|
||||
end vector;
|
||||
|
||||
-- def triRapide(L): # Quicksort
|
||||
-- if len(L) <= 1:
|
||||
-- return L
|
||||
-- pvt = L[0]
|
||||
-- L1, L2 = [], []
|
||||
-- for i in range(1, len(L)):
|
||||
-- if L[i] < pvt:
|
||||
-- L1.append(L[i])
|
||||
-- else:
|
||||
-- L2.append(L[i])
|
||||
-- return triRapide(L1) + [pvt] + triRapide(L2)
|
||||
|
||||
-- procedure Quick_Sort (A : in out Element_Array) is
|
||||
|
||||
-- procedure Swap(Left, Right : Index) is
|
||||
-- Temp : Element := A (Left);
|
||||
-- begin
|
||||
-- A (Left) := A (Right);
|
||||
-- A (Right) := Temp;
|
||||
-- end Swap;
|
||||
|
||||
-- begin
|
||||
-- if A'Length > 1 then
|
||||
-- declare
|
||||
-- Pivot_Value : Element := A (A'First);
|
||||
-- Right : Index := A'Last;
|
||||
-- Left : Index := A'First;
|
||||
-- begin
|
||||
-- loop
|
||||
-- while Left < Right and not (Pivot_Value < A (Left)) loop
|
||||
-- Left := Index'Succ (Left);
|
||||
-- end loop;
|
||||
-- while Pivot_Value < A (Right) loop
|
||||
-- Right := Index'Pred (Right);
|
||||
-- end loop;
|
||||
-- exit when Right <= Left;
|
||||
-- Swap (Left, Right);
|
||||
-- Left := Index'Succ (Left);
|
||||
-- Right := Index'Pred (Right);
|
||||
-- end loop;
|
||||
-- if Right = A'Last then
|
||||
-- Right := Index'Pred (Right);
|
||||
-- Swap (A'First, A'Last);
|
||||
-- end if;
|
||||
-- if Left = A'First then
|
||||
-- Left := Index'Succ (Left);
|
||||
-- end if;
|
||||
-- Quick_Sort (A (A'First .. Right));
|
||||
-- Quick_Sort (A (Left .. A'Last));
|
||||
-- end;
|
||||
-- end if;
|
||||
-- end Quick_Sort;
|
|
@ -27,4 +27,6 @@ package Vector is
|
|||
|
||||
procedure sort_with_index_desc(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural);
|
||||
|
||||
procedure quicksort(vec: in out T_Vecteur_Element; vec_index: in out T_Vecteur_Natural; a, b: in Natural);
|
||||
|
||||
end Vector;
|
||||
|
|
Loading…
Reference in a new issue