From b8acc073c1d116b2c9cdb63834b4de43ed758beb Mon Sep 17 00:00:00 2001 From: mysticbbs Date: Sat, 3 Mar 2012 22:08:07 -0500 Subject: [PATCH] Conditional function --- mdl/m_quicksort.pas | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mdl/m_quicksort.pas b/mdl/m_quicksort.pas index 7d6eedf..635f746 100644 --- a/mdl/m_quicksort.pas +++ b/mdl/m_quicksort.pas @@ -5,7 +5,7 @@ Unit m_QuickSort; Interface Const - mdlMaxSortSize = 5000; + mdlMaxSortSize = 10000; Type TSortMethod = (qAscending, qDescending); @@ -23,8 +23,9 @@ Type Constructor Create; Destructor Destroy; Override; - Function Add (Name: String; Ptr: LongInt) : Boolean; - Procedure Sort (Left, Right: Word; Mode: TSortMethod); + Function Add (Name: String; Ptr: Cardinal) : Boolean; + Procedure Conditional (Name: String; Ptr: Cardinal; ListMin: Word); + Procedure Sort (Left, Right: Word; Mode: TSortMethod); Procedure Clear; End; @@ -54,7 +55,7 @@ Begin Total := 0; End; -Function TQuickSort.Add (Name: String; Ptr: LongInt) : Boolean; +Function TQuickSort.Add (Name: String; Ptr: Cardinal) : Boolean; Begin Result := False; @@ -72,6 +73,20 @@ Begin Result := True; End; +Procedure TQuickSort.Conditional (Name: String; Ptr: Cardinal; ListMin: Word); +Var + Count : Word; +Begin + If Total < ListMin Then + Self.Add(Name, Ptr) + Else + For Count := Total DownTo 1 Do + If Data[Count].Name < Name Then Begin + Data[Count].Name := Name; + Data[Count].Ptr := Ptr; + End; +End; + Procedure TQuickSort.Sort (Left, Right: Word; Mode: TSortMethod); Var Temp : PQuickSortRec;