Pascal Pseudo Code

Page 1 of 1

1 Replies - 474 Views - Last Post: 30 March 2010 - 02:54 PM Rate Topic: -----

#1 Whiskers12345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-March 10

Pascal Pseudo Code

Posted 30 March 2010 - 01:51 PM

Trying to convert Pascal to C++ to sort an array of double numbers

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

Is This A Good Question/Topic? 0
  • +

Replies To: Pascal Pseudo Code

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,614
  • Joined: 23-August 08

Re: Pascal Pseudo Code

Posted 30 March 2010 - 02:54 PM

Duplicate of post in C/C++. Please do NOT create duplicate topics.

Closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1