Autor Beitrag
ruhrpott-desire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: So 24.02.08 14:16 
Hallo, ich möchte ein Array welches Wörter enthält Alphabetisch sortieren...

Mein Ansatz sieht so aus:

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:
procedure TForm1.sort;
var pos, kleinstepos, actualpos:integer;

procedure tausche;
var a:string;
begin
{ Tauschen der Zahlen im Array }
a:=Wortliste[kleinstepos].Wort;
Wortliste[kleinstepos].Wort:=Wortliste[actualpos].Wort;
Wortliste[actualpos].Wort:=a;
end;

begin
{ Hauptteil -Sort- }
pos:=1;
actualpos:=1;
while actualpos<>(AnzahlWoerter-1do
      begin

          kleinstepos:=actualpos;

          while pos<AnzahlWoerter do
          begin
             if Wortliste[kleinstepos].Wort>Wortliste[pos].Wort then
              begin
              kleinstepos:=pos;
              end;
          pos:=pos+1;
          end;

       tausche;
         actualpos:=actualpos+1;
      end;

end;


Ich komm aber irgendwie nicht weiter... der Anfang wird immer vertauscht und der Rest bleibt gleich..

Würde mich über Hilfe freuen ;)

Gruß
ruhrpott-desire

EDIT: Anzahl Wörter enthält die Zahl der Wörter im Arry, also wie lang es ist.
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: So 24.02.08 17:26 
Warum so kompliziert?
Kipp das ganze in eine TStringList. Die sortiert sich quasi von Alleine.
Cheers
Msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
ruhrpott-desire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: So 24.02.08 20:02 
Mh, eig. würd ichs lieber so machen, aber wie würde das mit der String list gehen? Aus der Hilfe werde ich nciht schlau...

Ich habs hinbekommen, war n kleiner aber feiner Fehler :P

Pos behielet den Anzahl Wörter - Wert.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 24.02.08 21:52 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  StringList: TStringList;
begin
  StringList := TStringList.Create;

  // Entweder...
  StringList.Add('Kiwi');
  StringList.Add('Apfel');
  StringList.Add('Birne');
  // ... oder ...
  StringList.LoadFromFile('C:\Obst.txt');

  StringList.Sort;
  ShowMessage(StringList.Text); // Resultat: "Apfel Birne Kiwi"

  StringList.Free;
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
ruhrpott-desire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: So 24.02.08 23:18 
Ah, gut zu wissen, aber dann habe ich die Ausgabe ja nicht mehr im Array, dann war meine prozedur ja doch nciht völlig sinnlos ;)

Gruß
Tobi