作業-排序程式 |
答題得分者是:christie
|
Kevin051
一般會員 發表:3 回覆:3 積分:1 註冊:2008-01-07 發送簡訊給我 |
|
christie
資深會員 發表:30 回覆:299 積分:475 註冊:2005-03-25 發送簡訊給我 |
procedure QuickSort(var A: array of Integer; iLo, iHi: Integer) ;
var Lo, Hi, Pivot, T: Integer; begin Lo := iLo; Hi := iHi; Pivot := A[(Lo Hi) div 2]; repeat while A[Lo] < Pivot do Inc(Lo) ; while A[Hi] > Pivot do Dec(Hi) ; if Lo <= Hi then begin T := A[Lo]; A[Lo] := A[Hi]; A[Hi] := T; Inc(Lo) ; Dec(Hi) ; end; until Lo > Hi; if Hi > iLo then QuickSort(A, iLo, Hi) ; if Lo < iHi then QuickSort(A, Lo, iHi) ; end; procedure TForm1.Button1Click(Sender: TObject); var intArray : array of integer; j:integer; T1,T2: Longword; SL:TStringList; begin SL:=TStringList.Create; SL.LoadFromFile('D:\input.txt'); SetLength(intArray,SL.Count) ; //Add values to intArray for j:=0 to sl.count-1 do intArray[j] := strtoint(sl[j]); t1:=GetTickCount; //We Sort here quicksort(intarray, Low(intArray), High(intArray)); t2:=GetTickCount; for j:=0 to SL.count -1 do SL[j]:=inttostr(intArray[j]); sl.savetofile('d:\output.txt'); caption:='Quick sort Completed, It Take milliseconds =' inttostr(t2-t1); SL.Free; end; ===================引 用 Kevin051 文 章=================== 1.資料結構裡面的排序方法任選 2.input.txt檔輸入 output.txt檔輸出 3.執行後要有排序時間 如多少秒
------
What do we live for if not to make life less difficult for each other? |
Kevin051
一般會員 發表:3 回覆:3 積分:1 註冊:2008-01-07 發送簡訊給我 |
===================引 用 christie 文 章=================== procedure TForm1.Button1Click(Sender: TObject); var intArray : array of integer; j:integer; T1,T2: Longword; SL:TStringList; begin SL:=TStringList.Create; SL.LoadFromFile('D:\input.txt'); SetLength(intArray,SL.Count) ; //Add values to intArray for j:=0 to sl.count-1 do intArray[j] := strtoint(sl[j]); t1:=GetTickCount; //We Sort here quicksort(intarray, Low(intArray), High(intArray)); t2:=GetTickCount; for j:=0 to SL.count -1 do SL[j]:=inttostr(intArray[j]); sl.savetofile('d:\output.txt'); caption:='Quick sort Completed, It Take milliseconds =' inttostr(t2-t1); SL.Free; end; sl.savetofile('d:\output.txt'); //路徑設置裡面能有中文嗎 如桌面等文字
編輯記錄
Kevin051 重新編輯於 2008-01-07 18:01:55, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |