comp.lang.ada
 help / color / mirror / Atom feed
* Desperatly trying to implement an mergesort algorithm
@ 2005-11-04 16:02 ejijott
  2005-11-04 16:22 ` Samuel Tardieu
  2005-11-04 18:48 ` Georg Bauhaus
  0 siblings, 2 replies; 5+ messages in thread
From: ejijott @ 2005-11-04 16:02 UTC (permalink / raw)


Hello!

Im having extreme problems trying to implement an mergesort in Ada, and
was hoping from some help in this group :)

My definition of the procedure is this:

type List is array(Natural range <>) of Integer;
.
.
procedure Mergesort(A : in out List);
.
.

And for readability I've used pastebin to host my code
(http://pastebin.com/417262)

I just plain and simply can't grasp what is wrong here! Am I even
partitioning the array properly?

(The merge part isn't complete yet)

Any help is GREATLY appreciated.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Desperatly trying to implement an mergesort algorithm
  2005-11-04 16:02 Desperatly trying to implement an mergesort algorithm ejijott
@ 2005-11-04 16:22 ` Samuel Tardieu
  2005-11-04 16:30   ` ejijott
  2005-11-04 18:48 ` Georg Bauhaus
  1 sibling, 1 reply; 5+ messages in thread
From: Samuel Tardieu @ 2005-11-04 16:22 UTC (permalink / raw)


>>>>> "ejijott" == ejijott  <ejijott@gmail.com> writes:

ejijott> I just plain and simply can't grasp what is wrong here!

This piece seems dubious to me:

                while i <= middle and then j <= A'last loop

I have only had a quick glance at your code, but "or else" would seem
much more logical than "and then" here. You don't want to stop when
one of the boundaries gets reached but when both of them are.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Desperatly trying to implement an mergesort algorithm
  2005-11-04 16:22 ` Samuel Tardieu
@ 2005-11-04 16:30   ` ejijott
  2005-11-05  3:33     ` Steve
  0 siblings, 1 reply; 5+ messages in thread
From: ejijott @ 2005-11-04 16:30 UTC (permalink / raw)


Does the partitioning look proper? With me using A'first and A'last?

mergesort(A(A'first .. middle));
mergesort(A(middle+1 .. A'last));




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Desperatly trying to implement an mergesort algorithm
  2005-11-04 16:02 Desperatly trying to implement an mergesort algorithm ejijott
  2005-11-04 16:22 ` Samuel Tardieu
@ 2005-11-04 18:48 ` Georg Bauhaus
  1 sibling, 0 replies; 5+ messages in thread
From: Georg Bauhaus @ 2005-11-04 18:48 UTC (permalink / raw)


ejijott@gmail.com wrote:

> I just plain and simply can't grasp what is wrong here! Am I even
> partitioning the array properly?

Could you write your reasoning below every declaration, statement,
and expression in yout program, as a comment?

Also, what text book or reference are you using?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Desperatly trying to implement an mergesort algorithm
  2005-11-04 16:30   ` ejijott
@ 2005-11-05  3:33     ` Steve
  0 siblings, 0 replies; 5+ messages in thread
From: Steve @ 2005-11-05  3:33 UTC (permalink / raw)


<ejijott@gmail.com> wrote in message 
news:1131121827.249591.288510@g14g2000cwa.googlegroups.com...
> Does the partitioning look proper? With me using A'first and A'last?
>
> mergesort(A(A'first .. middle));
> mergesort(A(middle+1 .. A'last));
>

The partitioning looks right to me.

Now a few questions:
  What is left_list for?  (looks like it could be deleted)
  What is right_list for? (looks like it could be deleted)

  In the while loop that does the merging, the smallest value of elements i 
and j are added sortarr, until one of the halves of the sublists is 
exhausted.  What happens to the remaining elements?

That's not your biggest problem:

Hint: If you change the procedure to

procedure Mergesort(A: List) ...

Your code will still compile.

Steve
(The Duck)





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-05  3:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-04 16:02 Desperatly trying to implement an mergesort algorithm ejijott
2005-11-04 16:22 ` Samuel Tardieu
2005-11-04 16:30   ` ejijott
2005-11-05  3:33     ` Steve
2005-11-04 18:48 ` Georg Bauhaus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox