From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5052a1cdc3cdb4ab X-Google-Attributes: gid103376,public From: Hans-Malte Kern Subject: Re: Quicksort Date: 1998/07/29 Message-ID: #1/1 X-Deja-AN: 375990379 References: <01bdbaef$d13c9340$86eba8c2@j.couston> To: Jamie Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: Informatik, Uni Stuttgart, Germany Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-07-29T00:00:00+00:00 List-Id: On 29 Jul 1998, Jamie wrote: On 29 Jul 1998, Jamie wrote: > Hi, > > I was wondering if anyone could help me out with some source code. I wish > to see a simple implementation of the Quicksort algorithm. As I'm still > a newcomer to Ada It would only have to deal with arrays of positive > integers - but please can you make it a recursive NOT iterative process. This one is taken from our informatic lecture procedure Q_Sort(Field: in out Field_Type) is procedure Local_Q_Sort(L, R: in Index_Typ) is Left, Right: Integer range Field'First-1 .. Field'Last-1; Pivot: Element_Type; begin Left:=L; Right:=R; Pivot:=Field((L+R)/2); --just take the midde while Left =< Right loop while Field(Left) < Pivot loop Left:=Left+1; end loop; while Field(Right) > Pivot loop Right:=Right-1; end loop; if Left =< Right then if Left < Right then swap(Field(Left), Field(Right)); end if; Left:=Left + 1; Right:=Right-1; end if; end loop; if LLeft then Local_Q_Sort(Left, R) end if; end Local_Q_Sort; begin Local_Q_Sort(Field'First, Field'Last); end Q_Sort; farvel jimmy --