Autor Beitrag
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Di 22.08.06 13:08 
Hallo,

ich möchte eine StringListe daraufhin prüfen, ob Sie identische Inhalte enthält und dann die identischen entfernt, bis nur noch der letzte vorhanden ist. Wie gehts das?

Ich probier schon eine Weile mit for-Schleifen rum, aber das wird nix.

cu

_________________
Das Unsympathische an den Computern ist, dass sie nur ja oder nein sagen können, aber nicht vielleicht.
DaiweL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 27



BeitragVerfasst: Di 22.08.06 13:35 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
i := 0;
while i < SList.Count
do begin
  j := i + 1;
  while(j < SList.Count)
  do begin
    if(SList[i] = SList[j])
    then SList.Delete(j);
    inc(j);
  end;
  inc(i);
end;


Voila...

Habs mal so aus dem Kopf geschrieben, also keine gartantie :P
Prinzip funktioniert aber so.

Man koente den Algo evt. optimieren indem man die Stringliste Sortiert, und dann die Eleminier schleife nur soweit gehen laesst bis S[i] <> S[j]

mfg
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Di 22.08.06 13:42 
Ich danke Dir, ich rätzel mir einen Wolf. :zustimm: Heut is net mein Tag! :P

Danke!!!!

_________________
Das Unsympathische an den Computern ist, dass sie nur ja oder nein sagen können, aber nicht vielleicht.
DaiweL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 27



BeitragVerfasst: Di 22.08.06 13:52 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
i := 0;
while i < SList.Count
do begin
  j := i + 1;
  while(j < SList.Count)
  do begin
    if(SList[i] = SList[j])
    then SList.Delete(j);
    !!!!!!!!!else inc(j);!!!!!!!!!!!
  end;
  inc(i);
end;




Sorry war ein Fehler...
Falls ein Eintrag geloescht wird, hat man ja automatisch den naechsten Eintrag am aktuelen Index:
Ohne Else inc(j) wuerde man bei jedem geloeschten Eintrag den darauffolgenden ueberspringen
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 22.08.06 14:48 
Moin!

Ich finde die Version von user profile iconmkinzler nachwievor ungeschlagen: guckst du. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.