(Turbo powers SysTools , ), . :
" / " , .
:
var
ListL : tStringList; // the left list
ListR : tSTringList; // the right list
ListA : tSTringList; // the Add List (should start empty)
ListD : tStringList; // the Delete list (should start empty)
iCurL : integer; // Left Cursor
iCurR : integer; // Right Cursor
iRes : integer; // result of compare
begin
iCurL := 0;
iCurR := 0;
ListL := tStringList.create;
ListR := tSTringList.create;
ListA := tSTringList.create;
ListD := tStringList.create;
InitAndLoadLists(ListL,ListR,ListA,ListD);
while (iCurL <= ListL.Count-1) and (iCurR <= ListR.Count-1) do
begin
iRes := CompareStr(ListL.Strings[iCurL],ListR.Strings[iCurR]);
if iRes = 0 then
begin
inc(iCurL);
inc(iCurR);
end;
if iRes < 0 then
begin
ListA.Add(ListL.Strings[iCurL]);
inc(iCurL);
end;
if iRes > 0 then
begin
listD.Add(ListR.Strings[iCurR]);
inc(iCurR);
end;
end;
while (iCurL <= ListL.Count-1) do
begin
listA.Add(ListL.Strings[iCurL]);
inc(iCurL);
end;
while (iCurR <= ListR.Count-1) do
begin
listD.Add(ListR.Strings[iCurR]);
inc(iCurR);
end;
ShowMessage( 'ADDS' + ^M+^J + ListA.Text);
ShowMessage( 'DELS' + ^M+^J + ListD.Text);
end;
The following code is what I used for testing. This is just an example, but in a real situation, I would build my keys so that they are correctly sorted, correctly fill in the numbers and force the case when it was necessary. If you use turbo boost sorting procedures, you can use TWO sort instead of two lists, but the end effect is the same.
procedure InitAndLoadLists(ListL, ListR, ListA, ListD: TStringList);
begin
ListL.Add('A,1');
ListL.Add('B,3');
ListL.Add('C,2');
ListR.Add('A,2');
ListR.Add('B,3');
ListR.Add('C,4');
end;
Edit: Code tested in Delphi 2009 and behaves correctly.
source
share