Pascal (pseudo code):
procedure insertsort(var r: list ; n : integer)
var j, i, save : integer;
begin
for i := n-1 downto 1 do
begin
j := i+1;
save := r[i];
r[n+1] := save;
while save > r[j] do
begin
r[j-1] := r[j];
j := j+1;
end
r[j-1] := save;
end;
end;
My C++ Version that does not work
void Insert(double A[], int &N)
{
int i, j;
double save;
for(i=0; i<N; i++)
{
j=i+1;
save=A[i];
A[N+1]=save;
while(save>A[j])
{
A[j-1] = A[j];
j++;
}
A[j-1]=save;
}
}
Current Output:
Insert Sort:
-6155.667 44.830 -7.117 70.028 -70.879
-41.304 -19.709 -25.004 17.377 26.585
any help would be appreciated...thank you

New Topic/Question
This topic is locked




MultiQuote




|