Autor Beitrag
CertainDeath
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Sa 31.05.08 08:18 
hi

ich arbeite noch nicht sehr lange mit delphi und brauch mal eure hilfe. ich habe 2 arrays und jetzt brauch ich eine ausgabe von allen inhalten die sich bei beiden arrays überschneiden.

mfg
huuuuuh
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 665
Erhaltene Danke: 19

win xp, (win vista), win 7
VS 2008 Express Edition, VS 2010 Express Edition, VS 2010 Professionell
BeitragVerfasst: Sa 31.05.08 09:06 
wie meinst du das?
zum einfachen vergleichen aller inhalte beider arrays hab ich selbst mal was gemacht mal sehn ob ichs finde....
CertainDeath Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Sa 31.05.08 09:14 
in beiden arrays sind integer zahlen enthalten und ich will die ausgeben, die auch in beiden arrays vorkommen.
DHE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 37

Win XP, Ubuntu 9.04
Delphi 7 PE; Delphi 2010 Prof (Dank AGS 2009 ;-) )
BeitragVerfasst: Sa 31.05.08 09:23 
user profile iconCertainDeath hat folgendes geschrieben:
in beiden arrays sind integer zahlen enthalten und ich will die ausgeben, die auch in beiden arrays vorkommen.


Sollen die Zahlen an der gleichen Stelle in beiden Arrays vorkommen oder sollen sie einfach nur in beiden Arrays vorhanden sein?
huuuuuh
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 665
Erhaltene Danke: 19

win xp, (win vista), win 7
VS 2008 Express Edition, VS 2010 Express Edition, VS 2010 Professionell
BeitragVerfasst: Sa 31.05.08 09:25 
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:
24:
25:
procedure vergleicheArrays;
var
 array1:array[1..10] of integer;
 array2:array[1..10] of integer;
 array3:array of integer;
 arraystringlist:tstringlist;
 i, j:integer;
begin
 i:=1;
 j:=1;
 repeat
 repeat
 if array1[i] = array2[j] then arraystringlist.AddStrings(inttostring(array1[i]));
 inc(j);
 until j>10;
 j:=1;
 inc(i);
 until i>10;
 i:=1)
 setlength(array3,arraystringlist.Count);
 repeat
 array3[i]:=strtoint(arraystringlist.strings[i]);
 inc(i);
 until i>arraystringlist.Count;
end;

*ungetestet* in paar minuten hingeschmiert
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 31.05.08 09:27 
Das würde grob so gehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
for a := 0 to length(Array1) - 1 do
  for b := 0 to length(Array2) - 1 do
    if Array2[b] = Array1[a] then
      Memo1.Lines.Add(Inttostr(Array1[a]) + ' ist in beiden Arras drin');

_________________
We are, we were and will not be.
CertainDeath Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Sa 31.05.08 09:32 
es soll einfach nur in beiden arrays enthalten sein, die position spielt für mich keine rolle.
danke euch beiden ich werde mal schauen ob ich damit zurechtkomme.
DHE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 37

Win XP, Ubuntu 9.04
Delphi 7 PE; Delphi 2010 Prof (Dank AGS 2009 ;-) )
BeitragVerfasst: Sa 31.05.08 09:41 
user profile iconCertainDeath hat folgendes geschrieben:
es soll einfach nur in beiden arrays enthalten sein, die position spielt für mich keine rolle.
danke euch beiden ich werde mal schauen ob ich damit zurechtkomme.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure VergleicheArrays(array1,array2 : array of Integer;  var ergebnis : array of Integer);
var len1,len2,i,o,len3 : Integer;
var buffer : array of Integer;
begin
      len1 := Length(array1);
      len2 := Length(array2);
      len3 := 0;

      for i := 0 to len1-1 do begin
            for o := 0 to len2-1 do begin
                  if array1[i] = array2[i] then begin
                        len3 := len3 + 1;
                        SetLength(buffer,len3);
                        buffer[len3-1] := array1[i];
                  end;
            end;
      end;

      for i := 0 to Length(buffer)-1 do ergebnis[i] := buffer[i];
end;


Sollte mit beliebig großen Arrays laufen