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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ea7ebea8b1d641f0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news1.tnib.de!feed.news.tnib.de!news.tnib.de!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Re: Quicksort algorithm in ada Date: Wed, 12 Apr 2006 14:22:37 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <443d040b$1@news.uni-rostock.de> NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1144851757 5784 2001:4bd8:0:666:280:adff:fe1e:79ba (12 Apr 2006 14:22:37 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Wed, 12 Apr 2006 14:22:37 +0000 (UTC) User-Agent: slrn/0.9.8.0 (Linux) Xref: g2news1.google.com comp.lang.ada:3788 Date: 2006-04-12T14:22:37+00:00 List-Id: * Thomas Krueger wrote: > Do you know the trick or a link to a good Ada implementation of quicksort. The classic algorithm is easy to implement. You are free to make it generic. with Ada.Text_IO; use Ada.Text_IO; procedure t is procedure qsort(f : in out String) is procedure swap(i,j : Positive) is t : Character := f(i); begin f(i) := f(j); f(j) := t; end swap; i : Natural := f'First; j : Natural := f'Last; begin if f'Length > 1 then while i f(j) then swap(i,j); j := Positive'Pred(j); exit; end if; i := Positive'Succ(i); end loop; while i f(j) then swap(i,j); i := Positive'Succ(i); exit; end if; j := Positive'Pred(j); end loop; end loop; qsort(f(f'First .. Positive'Pred(j))); qsort(f(Positive'Succ(i) .. f'Last)); end if; end qsort; buff : String(1 .. 80); last : Natural; begin Get_Line(buff, last); qsort(buff(buff'First .. last)); Put_Line(buff(buff'First .. last)); end t;