Autor Beitrag
THF
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Mi 27.04.05 10:38 
Hallo,

wie kann ich verschiedene Zahlen oder Variablen der Größe nach sortieren ?

Die größte Zahl soll oben stehen , die kleinste Zahl ganz unten .

Gruß

THF


Moderiert von user profile iconChristian S.: Topic aus CLX / Delphi Language (Object-Pascal) verschoben am Mi 27.04.2005 um 11:00
csigg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Mi 27.04.05 10:41 
Such hier oder generell im Netz (Wikipedia,google,..) mal mal nach Quicksort,Shakersort, Bubblesort,...
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 27.04.05 11:02 
Hallo!

Such doch mal hier im Forum nach Suche in: Delphi-Forum, Delphi-Library QUICKSORT OR SHAKERSORT OR BUBBLESORT.

Gruß
Tino
csigg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Mi 27.04.05 11:46 
@ tino: hätt ich auch so gemacht, weiss aber nicht wie ich so nen Link rein krieg :D
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 27.04.05 14:49 
user profile iconcsigg hat folgendes geschrieben:
weiss aber nicht wie ich so nen Link rein krieg :D

Hilfe » Beiträge schreiben und bearbeiten » BBCodes » Suchen ;-)
csigg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Mi 27.04.05 15:14 
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Mi 27.04.05 17:01 
Hallo,

welches ist am schnellsten ?

Ich muß nur ungefähr 30 - 40 verschiedene werte sortieren.

Gruß

Thf
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mi 27.04.05 17:26 
user profile iconTHF hat folgendes geschrieben:
Hallo,

welches ist am schnellsten ?

Ich muß nur ungefähr 30 - 40 verschiedene werte sortieren.

Gruß

Thf


Wenn das nur so wenige sind, spielt die Performance wohl kaum eine Rolle - nimm Bubblesort, der ist am einfachsten. Quicksort ist schneller, aber auch komplizierter.

Stefan
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Mi 27.04.05 21:16 
Hallo,

ich habe gelesen , daß Shell-Sort am schnellsten ist.

Stimmt das ?

Gruß

THF
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Mi 27.04.05 21:24 
user profile iconTHF hat folgendes geschrieben:
Hallo,

ich habe gelesen , daß Shell-Sort am schnellsten ist.

Stimmt das ?

Gruß

THF
Gewöhnlich ist Quicksort am schnellst. Aber wie gesagt, ist bei dieser Menge der Algorithmus völlig egal. Nimm das, was dir am einfachsten erscheint, zum Beispiel auch Sortieren durch Ersetzen (wie heisst das Fachwort?).

Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
csigg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 706

WIn XP, Win NT, Win2000, Suse8.0
Delphi 5, Delphi 6
BeitragVerfasst: Do 28.04.05 08:18 
Ich würde auch Sortieren durch Ersetzen oder Sortieren durch Ausweilen/Einfügen (weiss nicht mehr genau wie das heiß, gibts aber bei google und wikipedia genug dazu).
Auf schnelligkeit brauchst bei so kleiner Anzahl von Werten noch nicht achten, nimm einfach den Einfachsten, der dir selbst am besten gefällt, den du selbst am besten anpassen kannst.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 28.04.05 09:11 
Shellsort ist nicht am schnellsten. Quicksort ist in der Regel sehr schnell, kann in Einzelfällen aber genau so lange brauchen, wie die langsamen Verfahren Bubblesort oder Sortieren durch Auswahl.
Ein weiteres sehr schnelles Verfahren (aber auch komplizierter zu beschreiben und zu proggen) ist Heapsort. Zu allen Verfahren dürftest du aber Implementierungen hier im Forum finden.

Sinnvoll ist eine Auswahl des Sortierverfahrens aber erst ab 1000 Elementen oder so. Davor merkt man keinen Unterschied...

_________________
We are, we were and will not be.
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Fr 29.04.05 08:50 
hallo,

ich habe auch gelesen, daß Shell-Sort am schnellsten ist.

Ich muß zwar nur 30 -40 Werte sortieren ,

da die Procedure jedoch öfter aufgerufen wird, spielt die Geschwindigkeit doch eine

Rolle.

Ich glaube ich versuch es mit Shell-Sort.

Gruß

THF
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 29.04.05 09:18 
Gut, wenn ihr meint...Ich habe ja die Vorlesung Informatik3, in der ausführlich Sortierverfahren besprochen werden, nur 3mal korrigiert oder als Übungsgruppenleiter mitgemacht.
Shellsort ist nicht schlecht. Aber bitte sorge dann dafür, dass du als Inkremente alle Zahlen der Form 2^p*3^q nimmst. Dann kann man nämlich nachweisen, dass Shellsort eine Laufzeit von O(N*log^2(N)) hat. Allein diese Zahlen zu finden ist aber schon ein großer Programmieraufwand.

Quicksort dagegen ist im Mittel O(N*log(N)), und Heapsort auch im schlechtesten Fall O(N*log(N)).

Nimmt man hinzu, dass es zu Quicksort ungefähr drölftausend Implementierungen auch hier im Forum gibt... nun ja. Ist deine Sache. :roll:

_________________
We are, we were and will not be.
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Fr 29.04.05 18:33 
Hallo,

ich habe folgenden Code für Shell-Sort gefunden.

Ich blicke allerdings nicht durch wie ich das auf meine Strukturvariable

Variable[B].wert anwende.

Könnt Ihr mir da helfen ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure ShellSort(var a: array of real);
var bis,i,j,k : longint;
    h         : real;

begin
    bis := high(a);
    k   := bis shr 1;  { div 2 }
    While k > 0 do begin
        For i := 0 To bis - k do begin
            j := i;
            While (j >= 0And (a[j] > a[j + k]) do begin
                h   := a[j];
                a[j]:= a[j + k];
                a[j + k] := h;
                dec(j,k);
            end;
        end;
        k := k shr 1{ div 2 }
    end;
End;


Gruß

THF
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Fr 29.04.05 18:43 
was genau ist in Variable[B].wert?
ich vermute mal das ist ein record irgendeines typs

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Fr 29.04.05 19:08 
Hallo,

Variable[B].wert ist ein Record.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
Type
  TVariable = array [0..1000of record
...
...
Wert :Real;
end;


Gruß

THF
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Fr 29.04.05 19:24 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure ShellSort(var a: tvariable);
var bis,i,j,k : longint;
    h         : real;

begin
    bis := high(a);
    k   := bis shr 1;  { div 2 }
    While k > 0 do begin
        For i := 0 To bis - k do begin
            j := i;
            While (j >= 0And (a[j].wert > a[j + k].wert) do begin
                h   := a[j].wert;
                a[j].wert:= a[j + k].wert;
                a[j + k].wert := h;
                dec(j,k);
            end;
        end;
        k := k shr 1{ div 2 }
    end;
End

so werden allerdings nur die werte sortiert. willst du den ganzen array umsortieren, musst du deinen record typisieren:
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:
Type
  TmyRecord = record
   ...
   ...
   wert: real;
  end;  
 
  TVariable = array [0..1000of TmyRecord;

....

procedure ShellSort(var a: tvariable);
var bis,i,j,k : longint;
    h         : tmyrecord;

begin
    bis := high(a);
    k   := bis shr 1;  { div 2 }
    While k > 0 do begin
        For i := 0 To bis - k do begin
            j := i;
            While (j >= 0And (a[j].wert > a[j + k].wert) do begin
                h   := a[j];
                a[j]= a[j + k];
                a[j + k] := h;
                dec(j,k);
            end;
        end;
        k := k shr 1{ div 2 }
    end;
End;

so sollte es gehen, ist aber nicht getestet.

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Sa 30.04.05 00:16 
Hallo retnyg,

Danke für die Hilfe.

Ich muß das erst noch ausprobieren .

Gruß

THF
THF Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110

Vista
Delphi 2005 professional
BeitragVerfasst: Mo 02.05.05 09:34 
Hallo,

wie kann ich zusätzlich noch weitere Strukturvariablen desselben Records umsortieren.

zum Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
Type  
  TVariable = array [0..1000of record  
...  
...  
Wert :Real; 
Wert2:Integer;
Wert3:integer; 
end;

ausblenden 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:
procedure ShellSort(var a: tvariable);  
var bis,i,j,k : longint;  
    h         : real;  

 
begin  
    bis := high(a);  
    k   := bis shr 1;  { div 2 }  
    While k > 0 do begin  
        For i := 0 To bis - k do begin  
            j := i;  
            While (j >= 0And (a[j].wert > a[j + k].wert) do begin  
                h   := a[j].wert;  
                a[j].wert:= a[j + k].wert;  
                a[j].wert2:=a[j+k].wert2;
                a[j].wert3:=a[j+k].wert3;
                a[j + k].wert := h;  
                dec(j,k);  
            end;  
        end;  
        k := k shr 1{ div 2 }  
    end;  
End

Gibt es noch eine andere Möglichkeit ohne den Record zu typisieren ?
Gruß

THF