SortU.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:1k
- unit SortU;
- interface
- uses
- Classes;
- type
- TSortThread = class(TThread)
- private
- FSortArray: array of integer;
- protected
- procedure Execute; override;
- procedure Sort;
- public
- constructor Create(CreateSuspended: Boolean;var SortArray: array of Integer);
- published
- end;
- implementation
- constructor TSortThread.Create(CreateSuspended: Boolean;var SortArray: array of Integer);
- begin
- FSortArray := @SortArray;
- FreeOnTerminate := True;
- inherited Create(CreateSuspended);
- end;
- {当线程开始时,Execute方法将被调用。}
- procedure TSortThread.Execute;
- begin
- FreeOnTerminate := True;
- Sort;
- end;
- {下面实现了冒泡法排序}
- procedure TSortThread.Sort;
- var
- I, J, T: Integer;
- begin
- for I := High(FSortArray) downto Low(FSortArray) do
- for J := Low(FSortArray) to High(FSortArray) - 1 do
- if FSortArray[J] > FSortArray[J + 1] then
- begin
- T := FSortArray[J];
- FSortArray[J] := FSortArray[J + 1];
- FSortArray[J + 1] := T;
- if Terminated then Exit;
- end;
- end;
- end.