Example: |
The following program counts the number of exchanges which occur during the sorting process. The program first copies the first column of the data into the vector MyVec and then starts the sorting process. During the sorting the variable cnt is increased every time two cells of the vector are exchanged. Finally the count is displayed.
program CountSortOperations;
var
MyVec : TVector;
cnt : integer;
procedure MyVecSortExchange (Sender: TObject; ExchgWhat: byte; index1, index2, first, last: longint);
begin
inc(cnt);
end;
begin
cnt := 0;
MyVec := TVector.Create(nil);
DSTore.CopyDataColToVector (MyVec, 1, 0, 0, 1);
MyVec.OnSortExchange := @MyVecSortExchange;
MyVec.SortElems (true, 0, 0);
cout ('Number of Exchanges: ', cnt);
MyVec.Free;
end.
|