![]() |
Re: Prozedur anhalten, um Zwischenergebnisse zu sehen
Delphi-Quellcode:
Hallo,
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons; type TForm1 = class(TForm) ListBox1: TListBox; ListBox2: TListBox; Button1: TButton; Button2: TButton; Label1: TLabel; Label2: TLabel; Button3: TButton; procedure QuickSort(A: array of integer; iLo, iHi: Integer); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private {----} public {----} end; var Form1: TForm1; arr: array [0..10] of integer; a: array of integer; iLo, iHi: Integer; implementation {$R *.dfm} procedure TForm1.QuickSort(A: array of integer; iLo, iHi: Integer); var Lo, Hi, Mid, T: Integer; begin Lo := iLo; Hi := iHi; Mid := A[(Lo + Hi) div 2]; ShowMessage(IntToStr(Mid)+' '+IntToStr(Hi)+' '+IntToStr(Lo)); repeat while A[Lo] < Mid do Inc(Lo); while A[Hi] > Mid 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.Button2Click(Sender: TObject); var I: Integer; begin QuickSort(arr,Low(arr),High(arr)); for I:=Low(arr) to High(arr) do Listbox2.Items.Add(IntToStr(arr[I])); end; procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin Randomize; for I:=Low(arr) to High(arr) do arr[I]:=Random(100); for I:=Low(arr) to High(arr) do Listbox1.Items.Add(IntToStr(arr[I])); end; kann mir nochmal jemand helfen? Es wird jetzt überhaupt nicht mehr sortiert, aber ich kann die Showmessages zwischendrin abfangen! Ausgabe ist die gleiche wie unsortiert! |
Re: Prozedur anhalten, um Zwischenergebnisse zu sehen
Ich weiß auch nicht, was ich falsch mache, aber vorhin ging es noch und nun habe ich es soweit gebracht, dass es nicht mehr geht. Muss in die Listbox nicht das Array 'A'? Weil das 'arr' ist ja das gleiche wie vorher, oder?
|
Re: Prozedur anhalten, um Zwischenergebnisse zu sehen
Hai Futzel,
wenn ich das richtig sehe hast Du bei deinen Änderungen das VAR bei der Methoden deklaration herausgenommen. Dadurch werden die Änderungen die deine Quicksort-Funktion macht nicht an dein Array "arr" zurückgegeben. Also einfach mal so ändern ->
Delphi-Quellcode:
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons; type TForm1 = class(TForm) . . procedure QuickSort(VAR A: array of integer; iLo, iHi: Integer); . . procedure TForm1.QuickSort(VAR A: array of integer; iLo, iHi: Integer); . end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:57 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz