unit Programm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
PListe = ^TListe;
//Pointer deklariert
TListe =
record //Liste deklariert
key: Integer;
next: PListe;
text:
String;
end;
TForm1 =
class(TForm)
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
Button2: TButton;
Button3: TButton;
Edit2: TEdit;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Liste: PListe;
q: PListe;
i: integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
//Leere Liste
begin
liste :=
nil;
i:= 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
//Button für Listenerstellung am Kopf
begin
new(q);
i := i+1;
q.text := edit1.Text;
q.next := liste;
q.key := i;
liste := q;
end;
procedure TForm1.Button2Click(Sender: TObject);
//Button für Listenausgabe
begin
while liste <>
nil do begin
Listbox1.Items.Add(inttostr(liste.key) + '
: ' + liste.text);
liste := liste.next;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
// Button für Listenerstellung am Ende
var h:PListe;
begin
i := i+1;
if liste =
nil then begin
new(liste);
liste.text := edit1.Text;
Liste.key := i;
Liste.next :=
nil;
end else begin
h := liste;
while h.next <>
nil do begin
h := h.next;
end;
new(q);
h.next:= q;
q.text := edit1.Text;
q.key := i;
q.next :=
nil;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
//vor Key hinzufügen
var x: integer;
begin
x:= strtoint(edit2.Text);
while liste <>
nil do begin
if liste.key <> x
then begin
liste :=liste.next;
end else begin
i := i+1;
new(q);
q := liste;
liste.key := i;
liste.text := edit1.Text;
liste.next := q;
end;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
//hinter Key hinzufügen
var x: integer;
begin
x := strtoint(edit2.Text);
while liste <>
nil do begin
if liste.key <> x
then begin
liste := liste.next;
end else begin
i := i+1;
new(q);
q.next := liste.next;
liste.next := q;
q.key := i;
q.text := edit1.Text;
end;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
//Key löschen
var x: integer;
h: Pliste;
begin
x := strtoint(edit2.Text);
while liste <>
nil do begin
if liste.key <> x
then begin
liste := liste.next;
end else begin
h := liste.next;
liste.next := h.next;
liste.text := h.text;
liste.key := h.key;
end;
end;
end;
end.