Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MUtils;
- interface
- uses VCL.GRIDS, System.SysUtils, List;
- function MergeNonDescendingLists(ListA, ListB: TList): TList;
- procedure RandomizeSG(var E: TStringGrid);
- procedure ClearSG(var E: TStringGrid);
- function CheckIfNonDescendingAndCorrectSG(var E: TStringGrid): Boolean;
- implementation
- uses Winapi.Windows;
- function MergeNonDescendingLists(ListA, ListB: TList): TList;
- var
- Temp: TList;
- begin
- Temp := TList.Create;
- while (ListA.Next <> nil) or (ListB.Next <> nil) do
- begin
- if (ListA.Next <> nil) and (ListB.Next <> nil) then
- begin
- if ListA.Next.Val <= ListB.Next.Val then
- begin
- Temp.Add(ListA.Next.Val);
- ListA := ListA.Next;
- end
- else
- begin
- if ListB.Next <> nil then
- begin
- Temp.Add(ListB.Next.Val);
- ListB := ListB.Next;
- end;
- end;
- end
- else
- begin
- if ListA.Next <> nil then
- begin
- Temp.Add(ListA.Next.Val);
- ListA := ListA.Next;
- end
- else
- begin
- Temp.Add(ListB.Next.Val);
- ListB := ListB.Next;
- end;
- end;
- end;
- Result := Temp;
- end;
- function CheckIfNonDescendingAndCorrectSG(var E: TStringGrid): Boolean;
- var
- I: Integer;
- begin
- Randomize;
- with E do
- for I := 0 to ColCount - 2 do
- try
- if StrToInt(Cells[I + 1, 0]) < StrToInt(Cells[I, 0]) then
- begin
- Result := False;
- Exit;
- end;
- except
- MessageBox(0, PChar('List shouldn''t to contain empty fields.'),
- PChar('Warning!'), MB_ICONERROR);
- Result := False;
- Exit;
- end;
- Result := True;
- end;
- procedure RandomizeSG(var E: TStringGrid);
- var
- I, Buf: Integer;
- begin
- Randomize;
- with E do
- begin
- Buf := 1 + Random(ColCount);
- Cells[0, 0] := IntToStr(Buf);
- for I := 1 to ColCount - 1 do
- begin
- Buf := 1 + Random(ColCount) + StrToInt(Cells[I - 1, 0]);
- Cells[I, 0] := IntToStr(Buf);
- end;
- end;
- end;
- procedure ClearSG(var E: TStringGrid);
- var
- I: Integer;
- begin
- with E do
- for I := ColCount - 1 downto 0 do
- Cells[I, 0] := '';
- E.ColCount := 1;
- Exit;
- E.Rows[0].Clear;
- E.ColCount := 0;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement