Autor Beitrag
pL0pP0r
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 29.10.07 17:20 
Hallo,
Hab in Info die Aufgabe bekommen, Quicksort zu programmieren.
Mit Zufallszahlen generieren, 2 Listboxen und einem Button.
Ich denke ich habs bis jetzt auch richtig, jedoch schaff ich es nicht, dass er auf die Prozedur Quicksort zurückgreifen soll! Sprich, die Ausgabe, das Sortierte in der zweiten Listbox o0...

Bitte um Hilfe!


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ListBox2: TListBox;
    Button1: TButton;

    procedure Button1Click(Sender: TObject);

  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }
  end;
  const max=10;
var
l,r: integer;
  Form1: TForm1;
  zahl: array[1..10of integer;
implementation

{$R *.dfm}
procedure Quicksort(var zahl:array of integer; l,r: integer);
var i,j,hilf,m:integer;
begin
i:=l;
j:=r;
m:=Zahl[(l+r)div 2];            //Mitte ausrechnen

repeat
while zahl[i]<m do
while m<zahl[j] do           //findet erste Zahl die nicht ins Teilfeld gehört

if i<=j then
begin
hilf:=zahl[i];              //Vertauschen durch Hilfsvariable
zahl[i]:=zahl[j];
zahl[j]:=hilf;
inc(i);
dec(j);
end;
until i>j;
if l<j then quicksort(zahl,l,j);
if i<r then quicksort(zahl,i,r);
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j: integer;
begin
listbox1.Items.clear;
listbox2.Items.clear;
For i:=0 to max-1 do
begin
zahl[i]:=random(max);
listbox1.items.add(inttostr(zahl[i]));end;

for j:=0 to max-1 do
Listbox2.Items.Add(inttostr(zahl[i]));
end;

end.


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 29.10.07 17:46 
Moin und :welcome: im Forum!

a) Warum formatierst du deinen Code nicht (einrücken, etc.), der ist so unübersichtlich, dass du dich doch vermutlich selbst nicht darin zurechtfindest... :|

b) Du rufst nirgendwo die Quicksort-Funktion auf, dann kann das Feld auch nicht sortiert werden. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
pL0pP0r Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 29.10.07 18:30 
zu a) das sagt meine infolehrerin auch immer, aber ich seh ganz gut durch ;)

zu b) das is ja mein problem ^^... ich weiß nich wie ich das machen soll...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 29.10.07 18:32 
Moin!

user profile iconpL0pP0r hat folgendes geschrieben:
zu a) das sagt meine infolehrerin auch immer, aber ich seh ganz gut durch ;)
OK, da ich es nicht tue und damit deiner Lehrerin schützenhilfe gebe:
user profile iconpL0pP0r hat folgendes geschrieben:
zu b) das is ja mein problem ^^... ich weiß nich wie ich das machen soll...
...helfe ich dir weiter, wenn du den Code vernünftig formatiert hast. Deal? :zustimm: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
pL0pP0r Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 29.10.07 18:42 
oah wat? o0

Edit: Habs grad versucht... Aber der ordnet det immer automatisch wieder nach hinten...

hilfst mir bitte auch so? ;)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 29.10.07 18:48 
Moin!

user profile iconpL0pP0r hat folgendes geschrieben:
hilfst mir bitte auch so? ;)
Nein. ;) Ich verlange ja keinen Turmbau-zu-Babel, oder? :roll: :)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
pL0pP0r Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 29.10.07 18:51 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ListBox2: TListBox;
    Button1: TButton;

    procedure Button1Click(Sender: TObject);

  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }
  end;
  const max=10;
var
l,r: integer;
  Form1: TForm1;
  zahl: array[1..10of integer;
implementation

{$R *.dfm}
procedure Quicksort(var zahl:array of integer; l,r: integer);
var i,j,hilf,m:integer;
   begin
   i:=l;
   j:=r;
   m:=Zahl[(l+r)div 2];            //Mitte ausrechnen
repeat
   while zahl[i]<m do
   while m<zahl[j] do           //findet erste Zahl die nicht ins Teilfeld gehört
if i<=j then
   begin
   hilf:=zahl[i];              //Vertauschen durch Hilfsvariable
   zahl[i]:=zahl[j];
   zahl[j]:=hilf;
   inc(i);
   dec(j);
   end;
until i>j;
   if l<j then quicksort(zahl,l,j);
   if i<r then quicksort(zahl,i,r);
   end;

procedure TForm1.Button1Click(Sender: TObject);
var i,j: integer;
   begin
   listbox1.Items.clear;
   listbox2.Items.clear;
For i:=0 to max-1 do
   begin
   zahl[i]:=random(max);
   listbox1.items.add(inttostr(zahl[i]));end;
for j:=0 to max-1 do
   Listbox2.Items.Add(inttostr(zahl[i]));
   end;
   end.


Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt


Zuletzt bearbeitet von pL0pP0r am Mo 29.10.07 19:06, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 29.10.07 18:56 
Moin!

OK, du hast jetzt vorgeführt, dass du die Leertaste bedienen kannst. Könntest du jetzt bitte noch den Code ordentlich formatieren, so dass die Teile, die logische Abschnitte bilden, auf einer Einrückungsebene sind? Und beim nächsten Versuch bitte an die Delphi-Tags denken: einfach den gesamten Code markieren und auf das "+" neben "Delphi" oben im Editor klicken. ;)

"Vielen Dank für die Beachtung aller Sicherheitsmaßnahmen!" :)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
pL0pP0r Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 29.10.07 19:00 
wat fürn + ?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 29.10.07 19:03 
Moin!

user profile iconpL0pP0r hat folgendes geschrieben:
wat fürn + ?
Das hier ist keine automatische Hilfefunktion, wird sind Menschen; und im Gegensatz zur blödsinnig labernden Büroklammer verstehen wir die Worte "Hallo", "Bitte" und "Danke"... :|

Vorschlag: editiere doch einfach deinen letzten Code-Beitrag entsprechend, fertig. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
pL0pP0r Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Mo 29.10.07 19:08 
beantworte doch einfach die frage oder lass es sein o0

du weißt was ich will! man sieht im quelltext, was ich bis jez gemacht habe! was willst du mehr verdammt -.- ...

außerdem... blödsinn isses was du hier machst! ich programmier mit delphi, weil ich es muss! ich wollte nur ne einfache kleine frage stellen! und was is?????? mir wird erklärt, wie ich zeilen verrücke! weil man es ja "NICHT LESEN" kann... o0
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 29.10.07 19:12 
Viel Erfolg noch :wave:

_________________
There are 10 types of people - those who understand binary and those who don´t.
dummzeuch
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 593
Erhaltene Danke: 5


Delphi 5 ent, Delphi 6 bis Delphi XE8 pro
BeitragVerfasst: Mo 29.10.07 19:32 
user profile iconpL0pP0r hat folgendes geschrieben:
beantworte doch einfach die frage oder lass es sein
du weißt was ich will! man sieht im quelltext, was ich bis jez gemacht habe! was willst du mehr verdammt -.- ...


Vielleicht einen les- und verstehbaren Quellcode? Was erwartest Du? Wir werden hier nicht bezahlt, dafuer dass wir Dir helfen. Oder wie meine Oma schon sagte: "Wie man in den Wald hineinruft, so schallt es heraus."

Erstaunlich, meine Oma wusste schon mehr ueber das Verhalten in Foren als Du...
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 764
Erhaltene Danke: 127



BeitragVerfasst: Mo 29.10.07 19:50 
ALs erstes möchte ich mal narses und dummzeuch rechtgeben.
Quelltext sollte man auch formatieren, wenn man Delphi nur macht, weil man MUSS. Oh wie traurig:-(

Deine Fehler liegen hier:
ausblenden Delphi-Quelltext
1:
2:
   while zahl[i]<m do
   while m<zahl[j] do

Da müssen die beiden Variablen i und j verändert werden.
Und Aufrufen musst Du das Ding natürlich auch noch.
z.B. so
ausblenden Delphi-Quelltext
1:
Quicksort(Zahl,0,max-1);					

ub60