Autor Beitrag
theChaoS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: So 16.11.08 20:57 
Hallo alle miteinander

Okay bin mal wieder an meine Grenzen gestoßen und wehre Glücklich wen ihr mir mal helfen könntet
im Prinzip suche ich einen einfachen Sortieralgoriytmus also nix grosses ABER
ich habe einen Array (of String DYNAMISCH) wobei jede grade Zahl (0,2, bis n) ein Wort ist und jede ungrade Zahl (1,3,5 bis n) eine Integer Zahl die als String gespeichert ist.
Nun müssten die Zahlen sortiert werden ^^
Außerdem sollte jedes Wort das VOR der Zahl steht mit der Zahl verschoben werden das es am ende wieder VOR der Zahl steht^^

Ich selbst blicke da grad nicht mehr durch und bitte DRINGEND um Hilfe oder zu mindest ein Denkanstoss

Schon mal THX im Voraus

theCHaos
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: So 16.11.08 21:03 
Das hört sich irgendwie so an, als hättest du ein Designfehler in deiner Anwendung. Warum nimmst du nicht ein Array of Record, wobei das Record die Zahl und den String speichert? Und dieses Array of Record kannst du dann z.B. mit Bubblesort oder Quicksort sortieren. Kommt drauf an, wie groß das Array ist, und wie schnell das gehen soll. ;-)

_________________
We are, we were and will not be.
theChaoS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: So 16.11.08 21:08 
ähh tja also ne beispiel were gut ^^
so ne array of recod (in dynamicher vorm) hab ich noch nie verwendet
theChaoS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: So 16.11.08 22:50 
Tja also ich poste ma wie weit ich bin
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:
var j,i,a,b,help:integer;
c,d,strhelp:string;
begin
{i:=1;
repeat
listbox2.Items.Add(sortarray[i]);
i:=i+2;
until i=sa1-1;
listbox2.Items.Add(sortarray[i]);  }

// SORTIREN
i:=1
repeat
a:=strtoint(sortarray[i]);
b:=strtoint(sortarray[i+2]);
c:=sortarray[i-1];
d:=sortarray[i+1];
if a<b then
begin
help:=b;
a:=b;
b:=help;
strhelp:=d;
c:=d;
d:=strhelp;
sortarray[i]:=inttostr(a);
sortarray[i+2]:=inttostr(b);
end;
i:=i+2;
until i=sa1-1;

i:=1;   //EINLESEN
repeat
listbox2.Items.Add(sortarray[i-1]);
listbox2.Items.Add(sortarray[i]);
i:=i+2;
until i=sa1-1;
listbox2.Items.Add(sortarray[i-1]);
listbox2.Items.Add(sortarray[i]);


die Arrays sind GLOBAL
Tja also der diese suchverfahren arbeite aber FALSCH

P.S. jaja ich hab unleserlich gecodet
und ja die variablen sind unübersichtlich

Were cool von euch mir trozdem zu helfen ^^
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 764
Erhaltene Danke: 127



BeitragVerfasst: So 16.11.08 23:08 
Mach doch zwei Arrays draus (Strings und Zahlen). Sortiere dann das erste Array. Bei jeder Vertauschung im ersten Array tausche auch die entsprechenden Werte im zweiten Array.

ub60