[Overview][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'LCLProc' (#lcl)

MergeSort

Implements a merge/sort for TStrings or TFPList.

Declaration

Source position: lclproc.pas line 84

procedure MergeSort(

  List: TFPList;

  const OnCompare: TListSortCompare

); overload;

procedure MergeSort(

  List: TFPList;

  StartIndex: Integer;

  EndIndex: Integer;

  const OnCompare: TListSortCompare

); overload;

procedure MergeSort(

  List: TStrings;

  const OnCompare: TStringsSortCompare

); overload;

Arguments

List

  

The list of values to sort (overloaded type).

OnCompare

  

The sort compare function.

Arguments

List

  

The list of values to sort (overloaded type).

StartIndex

  

The initial entry in List used in the merge/sort.

EndIndex

  

The final entry in List used in the merge/sort.

OnCompare

  

The sort compare function.

Arguments

List

  

The list of values to sort (overloaded type).

OnCompare

  

The sort compare function.

Description

MergeSort is an overloaded routine used to implement a comparison-based sort routine for values in List. List can be a TStrings or TFPList instance. No actions are performed in the routine when List has not been assigned (contains Nil).

The StartIndex and EndIndex arguments allow the initial and final entries in a TFPList instance to be specified. When the values are omitted, they default to the first value (position 0) and the last value (Count-1) in List.

OnCompare is the comparison routine used to determine the order for the sorted values. It can be a TListSortCompare or TStringsSortCompare function, depending on the overloaded variant of the called routine.

MergeSort implements the J. von Nuemann divide-and-conquer algorithm, with an insertion sort used for lists with 6 or fewer elements.

See also

TListSortCompare

TStringsSortCompare

  

Specifies a comparison function type for string values in a TStrings instance.


Version 3.2 Generated 2024-02-25 Home