* Shell Sort
@ 2010-07-09 17:28 Shark8
2010-07-10 16:17 ` Shark8
0 siblings, 1 reply; 2+ messages in thread
From: Shark8 @ 2010-07-09 17:28 UTC (permalink / raw)
I'm having some trouble with a Shell Sort I'm writing; I think I
screwed up the internal insertion sort.
Type ARR is Array (Integer Range <>) of Integer;
Procedure Sort( Input : in out ARR ) is
Gaps : constant array(Positive Range <>) of Integer:=
(1, 4, 10, 23, 57, 132, 301, 701, 1750);
Initial_Gap_Index : Integer;
begin
If Input'Length > 1 then
For Index in reverse Gaps'Range loop
Initial_Gap_Index:= Index;
exit when Gaps(Initial_Gap_Index) < Input'Length;
end loop;
For GapIndex in reverse Gaps'First..Initial_Gap_Index loop
declare
Inc : Integer:= Gaps(GapIndex);
Index : Integer;
Temp : Integer;
begin
For Gap_Index in Input'First..Input'Last-Inc loop
Index:= Gap_Index;
Temp:= Input(Index);
while Index+Inc in Input'Range loop
if Temp >= Input(Index+Inc) then
Swap( Input, Index, Index+Inc );
end if;
Index:= Index + Inc;
end loop;
end loop;
end;
end loop;
end if;
end Sort;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Shell Sort
2010-07-09 17:28 Shell Sort Shark8
@ 2010-07-10 16:17 ` Shark8
0 siblings, 0 replies; 2+ messages in thread
From: Shark8 @ 2010-07-10 16:17 UTC (permalink / raw)
Never mind, I fixed it.
Procedure Sort( Input : in out ARR ) is
Gaps : constant array(Positive Range <>) of Integer:=
(1, 4, 10, 23, 57, 132, 301, 701, 1750);
Initial_Gap_Index : Integer;
begin
If Input'Length > 1 then
For Index in reverse Gaps'Range loop
Initial_Gap_Index:= Index;
exit when Gaps(Initial_Gap_Index) < Input'Length;
end loop;
For GapIndex in reverse Gaps'First..Initial_Gap_Index loop
Insertion:
declare
Inc : Integer:= Gaps(GapIndex);
Next : Integer;
Done : Boolean;
begin
while True loop
Done:= True;
For Index in Input'First..Input'Last-Inc loop --
First Element
Next:= Index + Inc; -- Next Element
if Input(Next) < Input(Index) then
Swap(Input, Index, Next); -- Not finished
Done:= False; -- ...keep goin`
end if;
end loop;
Exit When Done;
end loop;
end Insertion;
end loop;
end if;
end Sort;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-07-10 16:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-09 17:28 Shell Sort Shark8
2010-07-10 16:17 ` Shark8
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox