P1: ^integer;
2: ^real;
p1 integer, p2 real.
, , . ,
: ^integer, :
^ " " ".
- " ". , NIL. NIL , .
NIL . , p1 2 ,
p1:= NIL;
,
if 2 = NIL then ShowMessage(' 2 !');
, 2.
( ' , @). , .
:= @n;
, , . , p1 2 integer,
p2:= p1;
p1 2 .
, . , 1,
^: = 5;
i '. ^ , ' , -.
8.2.
, ' .
' new. new , ' . , real, new(p); ' real ( real), - ', .
, .
, , ' , , ". ', , Dispose, , .
, , ' new(p), dispose() '.
( 8.3) , .
|
|
˳ 8.3. ,
procedure TForm1.Button1Click(Sender: TObject); var p1,p2,p3: Integer; // integer begin // integer // ( ' ) New(p1); New(p2); New(p3); 1^:= 5; 2^:= 3; 3^:= 1^ + 2^; ShowMessage(' = ' + IntToStr(3^)); // // ( ', ) Dispose(p1); Dispose(2); Dispose(3); end; |
. , p1 2, . .
, .
(. 8.6).
. 8.6.
() , . . ' , , . , ' , '.
, , - . :
type TPStudent = ^TStudent; // TStudent // TStudent = record surname: string[20]; // name: string[20];' // ' group: integer; // address: string[60]; // next: TPStudent; // end; var head: TPStudent; // |
, . . . 8.7 .
ϳ head
. 8.7.
( 8.4) , . (. 8.8) (Button1).
. 8.8. ³ 1
˳ 8.4.
unit dlist1_;
Interface
Uses
Windows, Messages, SysUtils, Classes Graphics, Controls, Forms, Dialogs, StdCtrls;
Type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit; //
Edit2: TEdit; // '
Button1: TButton; //
Button2: TButton; //
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
Private
{ Private declarations }
public
{ Public declarations }
End;
Var
Form1: TForm1;
Implementation
{$R *.DFM)
Type
TPStudent=^TStudent; // TStudent
TStudent = record
f_name:string[20]; //
|
|
l_name: string [20]; // '
next: TPStudent; //
End;
Var
head: TPStudent; // ()
//
procedure TForm1.Button1Click(Sender: TObject);
Var
curr: TPStudent; //
Begin
new(curr); // '
curr^.f_name:= Edit1.Text;
curr^.1_nm:= Edit2.Text; //
curr^.next:= head;
head:= curr; //
Edit1.text:='';
Edit2.text: = ";
End;
//
procedure TForm1.Button2Click(Sender: TObject);
Var
curr: TPStudent; //
n:integer; // (- )
st:string; //
Begin
n:= 0;
st:= '';
curr:= head; //
while curr <> NIL dobegin
n:= n + 1;
st:= st + curr^.f_name + ' ' + curr^.1_name +#13;
curr:= curr^.next; //
end;
if n <> 0
then ShowMessage(':' + #13 + st)
else ShowMessage(' .');
End;
End.
TForm1.Button1Click, -, , , head.
TForm1.Button2Click, . curr. . ϳ , , curr next , curr. curr . , . , next (, curr) NIL.
, . . , , .
. , , , . . , , . , , (. 8.9).
. 8.9.
. 8.10. ij
8.5. 2
( 8.5, . 8.10) , . (Edit1 Edit2) (Button1) , .
˳ 8.5.
unit dlist2_;
Interface
Uses
Windows, Messages, SysUtils, Classes Graphics, Controls, Forms, Dialogs, StdCtrls;
Type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
End;
Var
Form1: TForm1;
Implementation
($R *.DFM}
|
|
Type
TPStudent=ATStudent; // TStudent
TStudent = record
f_name:string[20]; //
l_name:string[20]; // '
next: TPStudent; //
End;
Var
head: TPStudent; // ()
//
procedure TForm1.Button1Click(Sender: TObject);
var
node: TPStudent; //
curr: TPStudent; //
pre: TPStudent; // , curr,
Begin
new(node); //
node^.f_name:=Edit1.Text; //
node^.l_name:=Edit2.Text; // '
//
//
curr:=head;
pre:=NIL;
{ !
(node. f_name>curr". f__name) and (currONIL)
, curr = NIL , curr. *name !
,
(curr NIL),
FALSE, . }
while (curr NIL) and (node.f_name > curr^.f_name) do
Begin
//
pre:= curr;
curr:=curr^.next; //
End;
if pre = NIL then
Begin
//
node^. next: =head; head:=node;
End
Else
Begin
// pre,
curr node^.next:=re^.next;
r^.next:=node;
end;
Edit1.text:='';
Edit2.text:='';
Edit1.SetFocus;
End;
//
procedure TForm1.Button2Click(Sender: TObject);
Var
curr: TPStudent; //
n:integer; // (- )
at:string; //
Begin
n:=0;
st: = '';
curr:=head;
while curr <> NIL
Do
Begin
n:=n+1;
st:=st+curr^.f_name+' '+currA.l_name+#13;
curr:=curr^.next;
end;if n <> 0
then ShowMessage(': '+#13+st)
else ShowMessage(' .');
End;
//
procedure TForm1.FormActivate(Sender: TObject);
begin
head:=NIL; //
End;
End.
Tform1.Button1Click -, , , , next, .
. 8.11. ,
TForm1.Button2lick, . ϳ , , : , , , , . 8.11.
8.6.
, , , , (. 8.12).
. 8.12.
, ' . ', , , " ", dispose. dispose . ', , . ,
|
|
Var
: ^integer;
Begin
new(p);
{ }
dispose(p);
End
, . ', , . , , , ' .
. ij . 8.13.
, 2, .
TForm1.Button3Click, (Buttons). 8.6.
. 8.13. ³
3
˳ 8.6.
unit dlist2_;
interface
Uses
Windows, Messages, SysUtils, Classes Graphics, Controls, Forms, Dialogs,
StdCtrls;
Type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Var
Form1: TForm1;
Implementation
{$R *.DFM}
type
TPStudent=^TStudent; // TStudent
TStudent = record
f_name:string[20]; //
l_name:string[20]; // '
next: TPStudent; //
end;
var
head: TPStudent; // ()
procedure TForm1.Button1Click(Sender: TObject);
var
node: TPStudent; //
curr: TPStudent; //
pre: TPStudent; // , curr,
begin
new(node); //
node^.f_name:=Edit1.Text; //
node^.l_name:=Edit2.Text; // '
//
//
curr:=head;
pre:=NIL;
{ !
(node.f_name>curr^.f_name) and(curr<>NIL)
, curr = NIL , , curr.^name !
,
(curr <> NIL),
FALSE .}
while (curr <> NIL) and (node.f_name > curr^.f_name) do
begin //
pre:= curr;
curr:=curr^.next; //
end;
if pre = NIL
then
begin //
node^.next:=head;
head:=node;
end
else
begin // pre, curr
node^.next:=pre^.next;
pre^.next:=node;
end;
Edit1.text:='';
Edit2.text:='';
Edit1.SetFocus;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
curr: TPStudent; //
n:integer; // (- )
st:string; //
begin
n:=0;
st:='';
curr:=head;
while curr <> NIL do
begin
n:=n+1;
st:=st+curr^.f_name+' '+curr^.l_name+#13;
curr:=curr^.next;
end;
if n <> 0
then ShowMessage(':'+#13+st)
else ShowMessage(' .');
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
head:=NIL;
end;
End.
, . , . , , . , , , .
:
1. .
2. .
3. .
4. .
˳: