From: Shark8 <onewingedshark@gmail.com>
Subject: Shell Sort
Date: Fri, 9 Jul 2010 10:28:51 -0700 (PDT)
Date: 2010-07-09T10:28:51-07:00 [thread overview]
Message-ID: <a7c61cc8-a961-4406-89b3-a0c82e26e443@g19g2000yqc.googlegroups.com> (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;
next reply other threads:[~2010-07-09 17:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-09 17:28 Shark8 [this message]
2010-07-10 16:17 ` Shell Sort Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox