Wolfgang Bures
Wolfgang Bures

Reputation: 717

QuickSort Sortorder

I'm trying to implement quicksort for my library based on this post Delphi : Sorted List

I am not 100% sure how to implement a sort order ascending/descending into this.

Do I just switch the comperator in if Lo<=Hi then begin and until Lo>Hi;?

I admit I don't quite understand this.

Upvotes: 1

Views: 269

Answers (1)

Renate Schaaf
Renate Schaaf

Reputation: 315

You only need to reverse the comparison in these two lines

    while List[Lo] < Mid do Inc(Lo) ;
    while List[Hi] > Mid do Dec(Hi) ;

So make that

    while List[Lo] > Mid do Inc(Lo) ;
    while List[Hi] < Mid do Dec(Hi) ;

Upvotes: 1

Related Questions