請教有關數字比較之後排列由小到大順序問題 |
答題得分者是:Stallion
|
K1086
初階會員 發表:63 回覆:148 積分:42 註冊:2007-04-09 發送簡訊給我 |
請問 taishyang 站務副站長 小弟這樣貼上程式對嗎?
procedure TForm1.Button1Click(Sender: TObject); var i1,i2 : array[1..6] of integer; i,j : Integer; done : Boolean; s: String; begin i1[1]:= STRTOINT(Edit1.Text); i1[2]:= STRTOINT(Edit2.Text); i1[3]:= STRTOINT(Edit3.Text); i1[4]:= STRTOINT(Edit4.Text); i1[5]:= STRTOINT(Edit5.Text); i1[6]:= STRTOINT(Edit6.Text); for i := 1 to 6 do i2[1] := i1[1]; for i := low(i1) 1 to high(i1) do begin i2[i] := i1[i]; done := False; j := 1; repeat if i2[j] = i2[i] then begin i2[i] := i2[i] 1; j := 1; end else begin inc(j); if j >= i then done := True; end; until done; end; s := ''; for i := low(i1) to high(i1) do s := s IntTostr(i1[i]) ','; s := s Chr(13); for i := low(i2) to high(i2) do s := s IntTostr(i2[i]) ','; showmessage(s); end; end. ===>以上程式是輸入任何6組號碼做數字大小比較, 但當輸入完畢比較相同者 1之後,請問如何再加上SORT 可以由小到大排列秀出?? 謝謝! |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
我原封不動COPY你的程式,你可以觀察看看你PO的效果跟下面的效果哪種比較舒適^^ PO程式法的方式如下連結所示: http://delphi.ktop.com.tw/board.php?cid=32&fid=107&tid=86625 <textarea class="delphi" rows="10" cols="60" name="code">procedure TForm1.Button1Click(Sender: TObject); var i1,i2 : array[1..6] of integer; i,j : Integer; done : Boolean; s: String; begin i1[1]:= STRTOINT(Edit1.Text); i1[2]:= STRTOINT(Edit2.Text); i1[3]:= STRTOINT(Edit3.Text); i1[4]:= STRTOINT(Edit4.Text); i1[5]:= STRTOINT(Edit5.Text); i1[6]:= STRTOINT(Edit6.Text); for i := 1 to 6 do i2[1] := i1[1]; for i := low(i1) 1 to high(i1) do begin i2[i] := i1[i]; done := False; j := 1; repeat if i2[j] = i2[i] then begin i2[i] := i2[i] 1; j := 1; end else begin inc(j); if j >= i then done := True; end; until done; end; s := ''; for i := low(i1) to high(i1) do s := s IntTostr(i1[i]) ','; s := s Chr(13); for i := low(i2) to high(i2) do s := s IntTostr(i2[i]) ','; showmessage(s); end; end. </textarea> |
K1086
初階會員 發表:63 回覆:148 積分:42 註冊:2007-04-09 發送簡訊給我 |
===================引 用 taishyang 文 章=================== 我原封不動COPY你的程式,你可以觀察看看你PO的效果跟下面的效果哪種比較舒適^^ PO程式法的方式如下連結所示: http://delphi.ktop.com.tw/board.php?cid=32&fid=107&tid=86625 procedure TForm1.Button1Click(Sender: TObject); var i1,i2 : array[1..6] of integer; i,j : Integer; done : Boolean; s: String; begin i1[1]:= STRTOINT(Edit1.Text); i1[2]:= STRTOINT(Edit2.Text); i1[3]:= STRTOINT(Edit3.Text); i1[4]:= STRTOINT(Edit4.Text); i1[5]:= STRTOINT(Edit5.Text); i1[6]:= STRTOINT(Edit6.Text); for i := 1 to 6 do i2[1] := i1[1]; for i := low(i1) 1 to high(i1) do begin i2[i] := i1[i]; done := False; j := 1; repeat if i2[j] = i2[i] then begin i2[i] := i2[i] 1; j := 1; end else begin inc(j); if j >= i then done := True; end; until done; end; s := ''; for i := low(i1) to high(i1) do s := s IntTostr(i1[i]) ','; s := s Chr(13); for i := low(i2) to high(i2) do s := s IntTostr(i2[i]) ','; showmessage(s); end; end. <textarea class="delphi" rows="10" cols="60" name="code"> procedure TForm1.Button1Click(Sender: TObject); var i1,i2 : array[1..6] of integer; i,j : Integer; done : Boolean; s: String; begin i1[1]:= STRTOINT(Edit1.Text); i1[2]:= STRTOINT(Edit2.Text); i1[3]:= STRTOINT(Edit3.Text); i1[4]:= STRTOINT(Edit4.Text); i1[5]:= STRTOINT(Edit5.Text); i1[6]:= STRTOINT(Edit6.Text); for i := 1 to 6 do i2[1] := i1[1]; for i := low(i1) 1 to high(i1) do begin i2[i] := i1[i]; done := False; j := 1; repeat if i2[j] = i2[i] then begin i2[i] := i2[i] 1; j := 1; end else begin inc(j); if j >= i then done := True; end; until done; end; s := ''; for i := low(i1) to high(i1) do s := s IntTostr(i1[i]) ','; s := s Chr(13); for i := low(i2) to high(i2) do s := s IntTostr(i2[i]) ','; showmessage(s); end; end. </textarea> 小弟再 上傳測試一下 |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
應該是作業吧!覺得你還算用心動手作了前半部,另外簡單的資料結構應該都有教氣泡排序,快速排序法等等,下次要自己多GOOGLE一下喔~附上一個簡單的範例(已測試過)。
<textarea cols="60" rows="10" class="delphi" name="code"> Procedure BubbleSort(var List:array of integer); var i,j,Temp:integer; begin for i := low(list) to high(list)-1 do begin for j := low(list) to high(list) -1 do begin if List[j] > List[j 1] then begin Temp := List[j]; List[j] := List[j 1]; List[j 1] := Temp; end; end; end; end; procedure TForm1.Button1Click(Sender: TObject); var i1,i2 : array[1..6] of integer; i,j : Integer; done : Boolean; s: String; begin i1[1]:= STRTOINT(Edit1.Text); i1[2]:= STRTOINT(Edit2.Text); i1[3]:= STRTOINT(Edit3.Text); i1[4]:= STRTOINT(Edit4.Text); i1[5]:= STRTOINT(Edit5.Text); i1[6]:= STRTOINT(Edit6.Text); for i := 1 to 6 do i2[1] := i1[1]; for i := low(i1) 1 to high(i1) do begin i2[i] := i1[i]; done := False; j := 1; repeat if i2[j] = i2[i] then begin i2[i] := i2[i] 1; j := 1; end else begin inc(j); if j >= i then done := True; end; until done; end; BubbleSort(i1); BubbleSort(i2); s := ''; for i := low(i1) to high(i1) do s := s IntTostr(i1[i]) ','; s := s Chr(13); for i := low(i2) to high(i2) do s := s IntTostr(i2[i]) ','; showmessage(s); end; </textarea> |
K1086
初階會員 發表:63 回覆:148 積分:42 註冊:2007-04-09 發送簡訊給我 |
<textarea class="delphi" rows="10" cols="60" name="code">procedure TForm1.Button1Click(Sender: TObject);
var i,j,Temp:integer;
list:array[1..6] of integer;
s: String;
begin
list[1]:= STRTOINT(Edit1.Text);
list[2]:= STRTOINT(Edit2.Text);
list[3]:= STRTOINT(Edit3.Text);
list[4]:= STRTOINT(Edit4.Text);
list[5]:= STRTOINT(Edit5.Text);
list[6]:= STRTOINT(Edit6.Text);
begin
s:='';
for i := low(list) to high(list)-1 do
begin
for j := low(list) to high(list)-1 do
begin
if List[j] > List[j 1] then
begin
Temp := List[j];
List[j] := List[j 1];
List[j 1] := Temp;
end;
s := s IntTostr(List[j 1]) ',';
Label1.Caption := s;
end;
end;
end;
end;
end.</textarea>
===================引 用 Stallion 文 章=================== 應該是作業吧!覺得你還算用心動手作了前半部,另外簡單的資料結構應該都有教氣泡排序,快速排序法等等,下次要自己多GOOGLE一下喔~附上一個簡單的範例(已測試過)。 <textarea class="delphi" rows="10" cols="60" name="code">Procedure BubbleSort(var List:array of integer); var i,j,Temp:integer; begin for i := low(list) to high(list)-1 do begin for j := low(list) to high(list) -1 do begin if List[j] > List[j 1] then begin ????Temp := List[j]; ????List[j] := List[j 1]; ????List[j 1] := Temp; end; end; end; end; procedure TForm1.Button1Click(Sender: TObject); var i1,i2 : array[1..6] of integer; i,j : Integer; done : Boolean; s: String; begin i1[1]:= STRTOINT(Edit1.Text); i1[2]:= STRTOINT(Edit2.Text); i1[3]:= STRTOINT(Edit3.Text); i1[4]:= STRTOINT(Edit4.Text); i1[5]:= STRTOINT(Edit5.Text); i1[6]:= STRTOINT(Edit6.Text); for i := 1 to 6 do ???? i2[1] := i1[1]; for i := low(i1) 1 to high(i1) do begin i2[i] := i1[i]; done := False; j := 1; repeat if i2[j] = i2[i] then begin ????i2[i] := i2[i] 1; ????j := 1; end else begin ????inc(j); ????if j >= i then ???? done := True; end; until done; end; BubbleSort(i1); BubbleSort(i2); s := ''; for i := low(i1) to high(i1) do ???? s := s IntTostr(i1[i]) ','; s := s Chr(13); for i := low(i2) to high(i2) do ???? s := s IntTostr(i2[i]) ','; showmessage(s); end; </textarea><br /> 請問尊榮會員 小弟修改上列程式為何 還是不行,請教那裡錯了?? |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
adonis
高階會員 發表:140 回覆:258 積分:159 註冊:2002-04-15 發送簡訊給我 |
|
K1086
初階會員 發表:63 回覆:148 積分:42 註冊:2007-04-09 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |