Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (7)


Quick SortFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Algorithm
Skill Level:
Scoring:
Last Update:
02/27/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet quick sort array
Times Scored:
7
Visits:
4893
Uploader: Sébastien Charest
Company:
Reference: N/A
 
Question/Problem/Abstract:
How to quick sort an array?
Answer:



This came from the TThread demo of Delphi

Modify it for your code...i think it can be very helpfull, it's very fast! if it's reposrt say it to me i'll remove it...please gimme some COMMENT, it's my first submit :P

to be less lost go see the demo..

sorry for my bad english :P

procedure Sort(var A: array of Integer);

  procedure QuickSort(var A: array of Integer; iLo, iHi: Integer);
  var
    Lo, Hi, Mid, T: Integer;
  begin
    Lo := iLo;
    Hi := iHi;
    Mid := A[(Lo + Hi) div 2];
    repeat
      while A[Lo] < Mid do Inc(Lo);
      while A[Hi] > Mid do Dec(Hi);
      if Lo <= Hi then
      begin
        T := A[Lo];
        A[Lo] := A[Hi];
        A[Hi] := T;
        Inc(Lo);
        Dec(Hi);
      end;
    until Lo > Hi;
    if Hi > iLo then QuickSort(A, iLo, Hi);
    if Lo < iHi then QuickSort(A, Lo, iHi);
    if Terminated then Exit;
  end;

begin
  QuickSort(A, Low(A), High(A));
end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Useless..
    Jos Visser (Jun 27 2003 4:07PM)

I think it's pretty useless to post a quicksort routine here, without any explanation. Delphi's TStringList class has a QuickSort of it's own, so no need to repost it here..

It would have been nice if you told us some more about the technique quicksort uses or even give a few examples on how and when to use it.
Respond

RE: Useless..
altuð kayýþoðlu (Dec 5 2004 2:23AM)

i agree that there is little explanation etc etc but it is not useless. at least it did my work. thanks Sebastién for your article :)
Respond

Try searching Delphi 3000 before posting.
    Caiber (Mar 3 2003 3:15PM)

You should really try searching for articles that already cover what you are talking about, there are at least three already under "Quick Sort".
For example...this article atleast has some valid reasons for re introducing a common and already implemented algorithm.

http://www.delphi3000.com/articles/article_1720.asp

Enjoy..
Respond

Is it really important...
    Daniel Wischnewski (Feb 28 2003 3:08PM)

to be posted here? Well I'm nt quite sure, since everyone has the source installed with Delphi together.

I think it may be useful, once you describe a little how it works. Just the source does not help any one any more, than having it on the computer in the Demo Path of Delphi, or does it?
Respond

RE: Is it really important...
Sébastien Charest (Mar 1 2003 12:35AM)

yeah you're right...i'll explain it when i'll hace the time...but i think that it's good to be here even if it came with the demo of Delphi...because it's not a QuickSort demo...it's in a a demo that take this to show something else...


dunno if you understand...my english is so bad....sorry!
Respond

Quicksort
    Hans Pieters (Feb 28 2003 11:56AM)

Examples like this show us the beauty of programming languages like Pascal.  Are this examples useful? Not when you see it as just another  sort routine: too much is happening in those simple 10 lines of code. You could easely write a 50 page annotation on this and really be stunned when you see the inginuity behind it...
Hans Pieters
Respond

RE: Quicksort
rasha (Dec 4 2004 3:17PM)

i want to learn about fast quick sort in pascal language
can you help me
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
Peganza
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)