Autor Beitrag
tomekkkk
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Do 04.09.08 22:38 
Telefonbuch
HAb die aufgabe ein telefonbuch zu programmieren ... das hab ich bis jetzt alles geschafft aber
wenn ich das telefonbuch(array[Vorname Nachname Telenummer]) z.B. nach vornamen sortieren will dann werden alle telefonnummern und nachnamen gemischt... kriegt man das hin das telefonnummer nach sortieren immernoch bei seiner dimension im array passt
hier quelltext von den befehlen die ich bis jetzt habe:
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 TForm1.btn_vornameClick(Sender: TObject);
var i,j : Integer;
help : string;
begin

     for i:=1 to speicherplaetze do
     begin
         for j:=1 to speicherplaetze-1 do
         begin
              if eintrag[j,1] > eintrag[j+1,1then
              begin
              help:=eintrag[j+1,1];
              eintrag[j+1,1]:=eintrag[j,1];
              eintrag[j,1]:=help;
             end;
         end;
     end;

for i:=1 to speicherplaetze do
    begin
    stringgrid1.cells[1,i] := eintrag[i,1];
    stringgrid1.cells[2,i] := eintrag[i,2];
    stringgrid1.cells[3,i] := eintrag[i,3];
    end;
end;

also telefonnummer und name sollten zusammenbleiben nach dem sortieren das ich das in dem stringgrid ausgeben kann...
Dazu hab ich noch 2 bilder gemacht wie der das macht wie es vorm sortieren aussieht und wie danache:

Moderiert von user profile iconNarses: Bilder als Anhang hochgeladen

hab schon überall gegoogled aber nix gefunden
danke schonma =) lg tomek
Einloggen, um Attachments anzusehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 04.09.08 22:56 
Moin und :welcome: im Forum!

Du musst beim Dreieckstausch alle zugehörigen Einträge mit tauschen:
user profile icontomekkkk hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
     for i:=1 to speicherplaetze do
     begin
         for j:=1 to speicherplaetze-1 do
         begin
              if eintrag[j,1] > eintrag[j+1,1then
              begin
              help:=eintrag[j+1,1];
              eintrag[j+1,1]:=eintrag[j,1];
              eintrag[j,1]:=help;
              help:=eintrag[j+1,2];
              eintrag[j+1,2]:=eintrag[j,2];
              eintrag[j,2]:=help;
              help:=eintrag[j+1,3];
              eintrag[j+1,3]:=eintrag[j,3];
              eintrag[j,3]:=help;
             end;
         end;
     end;
cu ;)
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
tomekkkk Threadstarter
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Do 04.09.08 23:00 
wow danke für die schnelle antwort ich hatte da irgendwie eine blockade beim denken =D
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Do 04.09.08 23:04 
So wie narses sagt würde es gehen, oder du definierst einen eigenen datentyp als record, etwa so:

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:
type TEintrag = record
  name,telefon,vorname: string;
end;

var
  eintrag: array[0..255of tEintrag;

procedure TForm1.btn_vornameClick(Sender: TObject);
var i,j : Integer;
help : TEintrag;
begin

     for i:=1 to speicherplaetze do
     begin
         for j:=1 to speicherplaetze-1 do
         begin
              if eintrag[j].name > eintrag[j+1].name then
              begin
              help:=eintrag[j+1];
              eintrag[j+1]:=eintrag[j];
              eintrag[j]:=help;
             end;
         end;
     end;

for i:=1 to speicherplaetze do
    begin
    stringgrid1.cells[1,i] := eintrag[i].name;
    stringgrid1.cells[2,i] := eintrag[i].vorname;
    stringgrid1.cells[3,i] := eintrag[i].telefon;
    end;
end;


("blind" getippt, hoffe es stimmt)

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)