comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Quick Sort in Rosetta Code
Date: Wed, 10 Feb 2016 20:41:23 +0000
Date: 2016-02-10T20:41:23+00:00	[thread overview]
Message-ID: <lylh6s5mdo.fsf@pushface.org> (raw)
In-Reply-To: 2e3f8f3d-9247-4294-9ee7-961547674bc3@googlegroups.com

gautier_niouzes@hotmail.com writes:

> Couldn't not find how to reach the author of the Rosetta Code Quick Sort code
>   http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Ada
> ...but the code needs some improvement.
>
> If you put 
>       Wed => 99.0, 
> in the demo instead of
>       Wed => 800.0, 
> you get
>    99.00  100.00  300.00  200.00  500.00  700.00  900.00

Yes.

I thought this might be an interesting introduction to gnatprove (GPL
2015), and was disappointed to find that it doesn't support quantified
expressions! so you have fun writing them out longhand, which means in
the body.

I have no idea why the C code at rosettacode.org works and the Ada
doesn't, and it's not helped by having no idea what the partitioning
loop is trying to do! which makes it hard to write assertions.

   void quick_sort (int *a, int n) {
       int i, j, p, t;
       if (n < 2)
           return;
       p = a[n / 2];
       for (i = 0, j = n - 1;; i++, j--) {
           while (a[i] < p)
               i++;
           while (p < a[j])
               j--;
           if (i >= j)
               break;
           t = a[i];
           a[i] = a[j];
           a[j] = t;
       }
       quick_sort(a, i);
       quick_sort(a + i, n - i);
   }

      parent reply	other threads:[~2016-02-10 20:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-10  5:27 Quick Sort in Rosetta Code gautier_niouzes
2016-02-10  5:43 ` Jeffrey R. Carter
2016-02-10 13:50   ` robin.vowels
2016-02-10 21:39     ` Jeffrey R. Carter
2016-02-10  7:00 ` Leo Brewin
2016-02-10  7:14 ` Leo Brewin
2016-02-10 10:04   ` gautier_niouzes
2016-02-10 10:16   ` gautier_niouzes
2016-02-10 20:41 ` Simon Wright [this message]
replies disabled

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