Autor Beitrag
asbito
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Mo 27.10.08 18:14 
HI @all

Ich hab ein kleines problem ich soll nen programm schreiben das mit na doppelt verketetten Liste funktioniert.
Jetzt ist das problem, das ich quasi das aktuelle element geslöscht werden soll.
Aber ich weiss net wie ich das machen soll.

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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
type
  tInhalt=String[50];
  tzeiger= ^tknoten;
  tknoten = record
    Inhalt : tInhalt;
    zNach : tZeiger;
    zVor : tZeiger;
  end;

Var
  zKopf : tZeiger;
  zAktuell: tZeiger;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  zKopf := NIL;
  zAktuell := NIL;
end;

procedure TForm1.Button1Click(Sender: TObject);
var zNeu,zAlt,zHilf: tZeiger;
begin
  new(zNeu);
  zNeu^.Inhalt:=InputBox('Hinzufügen','Hinzufügen','');
  zNeu^.zNach := NIL;
  if zKopf = NIL
    then begin
      zKopf := zNeu;
      zKopf^.zVor := NIL;
      zAktuell := zKopf;
  end
    else begin
      new(zHilf);
      zHilf := zAktuell;
      zAktuell^.zNach := zNeu;
      zAktuell := zNeu;
      zAktuell^.zVor := zHilf;

    end;

  Edit1.Text := zAktuell.Inhalt;

end;

procedure TForm1.Button3Click(Sender: TObject);
var zhilf : tzeiger;
begin
  new(zHilf);
  zHilf := zAktuell;
  if zAktuell^.zVor <> NIL
    then begin
      Edit1.Text := zAktuell^.zVor.Inhalt;
      zAktuell:= zHilf^.zVor;
    end
  else Showmessage('Ende der Liste');
end;

procedure TForm1.Button2Click(Sender: TObject);
var zHilf: tZeiger;
begin
  new(zHilf);
  zHilf := zAktuell;
  if zAktuell^.zNach <> NIL
    then begin
      Edit1.Text := zaktuell^.zNach.Inhalt;
      zAktuell := zHilf^.zNach;
    end
  else ShowMessage('Ende der Liste');
end;

procedure TForm1.Button4Click(Sender: TObject);
Var zHilf: tzeiger;
begin
  new(zHilf);
  zHilf := zAktuell.zNach;
  zAktuell^.zVor := zHilf;
  dispose(zAktuell);  //Geschrieben von Tobias Franz
end;


bei button 4 hab ich das lösch problem.

helft mir ma bitte.

lg asbito.

p.s. hab ma meinen namen in den quelltext gesetzt nicht das meine lehrerin das sieht und sagt das is nicht von mir ^^.
Xabitire
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 114

Win Xp, Win Vista
D6 PE, D7 PE
BeitragVerfasst: Mo 27.10.08 18:32 
So sollte es eigenlich funktionieren: (ungetestet)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button4Click(Sender: TObject);
begin
  zAktuell.zNach^.zVor := zAktuell.zVor;
  zAktuell.zVor^.zNach := zAktuell.zNach;
  dispose(zAktuell);
end;


Dann brauchst du auch kein zHilf! :wink:

MFG Blackbird8690
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.10.08 18:43 
Aber in beiden Fällen vorher auf nil prüfen.
asbito Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Mo 27.10.08 19:12 
heee danke.

hat gut funktioniert.

llg asbito.