Похожие презентации:
14_Двоичное (бинарное) дерево(часть 2)
1. Двоичное (бинарное) дерево
(часть 2)1
2. Процедура obxod
Процедура обходит узел дерева в следующем порядке:- левое поддерево;
- узел;
- правое поддерево
и выводит хранящиеся в узлах значения чисел
procedure obxod (r1:point);
const limit=100;
максимальное число адресов разветвлений, которые
могут храниться одновременно
var this: point;
no : 0 .. limit; no - номер адреса
adr: array [1..limit] of point; массив адресов
begin
1 this:=r1;
2 no:= 0 ;
2
3. Процедура obxod
Обход продолжается, пока либо есть куда спускаться, т.е. this<>nil, либоостались необработанные разветвления (узлы), т.е. no<> 0
3 while (this <> nil) or (no <> 0 ) do begin
4
if this <>nil then begin
5
no:= no + 1;
6
adr [no]:= this;
7
this:= this^.l
8
end
(* then *)
9
else begin
т.е. обход поддеревьев окончен this=nil; извлекается последний из
запомненных адресов разветвления, выводится значение из этого узла и
осуществляется спуск по правой ветви
10
this:=adr [no];
11
no:=no-1;
12
Memo1.Lines.Add(inttostr(this^.a));
13
this:=this^.r
14
end
(* else *)
15
end
(* while *)
16 end;
3
4.
Процедураthis
obxod
no= 0+1=1
adr [1]= адрес 4
r1
this^.l
4
. 2
.
.
2
1
2
3
4
5
6
7
8
7
. 6
.
this:=r1;
no:= 0 ;
while (this <> nil) or (no <> 0 ) do begin
if this <>nil then begin
no:= no + 1;
adr [no]:= this;
this:= this^.l
end
.
8
.
4
5.
Процедураobxod
this
r1
no= 1
adr [1]= адрес 4
this^.l
4
. 2
.
.
2
3
4
5
6
7
8
7
. 6
.
.
8
.
while (this <> nil) or (no <> 0 ) do begin
if this <>nil then begin
no:= no + 1;
adr [no]:= this;
this:= this^.l
end
5
6.
Процедураobxod
r1
this
no= 1
adr [1]= адрес 4
4
this^.l
. 2
.
.
2
3
4
5
6
7
8
7
. 6
.
.
8
.
while (this <> nil) or (no <> 0 ) do begin
if this <>nil then begin
no:= no + 1;
adr [no]:= this;
this:= this^.l
end
6
7.
Процедураobxod
.
r1
this
adr [1]= адрес 4
no= 1+1=2
adr [2]= адрес 2
4
this^.l
. 2
.
.
2
3
4
5
6
7
8
7
. 6
.
.
8
.
while (this <> nil) or (no <> 0 ) do begin
if this <>nil then begin
no:= no + 1;
adr [no]:= this;
this:= this^.l
end
7
8.
Процедураobxod
.
this
4
. 2
.
.
2
3
4
5
6
7
8
no= 2
adr [1]= адрес 4
adr [2]= адрес 2
r1
7
. 6
.
.
8
.
while (this <> nil) or (no <> 0 ) do begin
if this <>nil then begin
no:= no + 1;
adr [no]:= this;
this:= this^.l
end
8
9.
Процедураobxod
adr [1]= адрес 4
no= 2
adr [2]= адрес 2
no= 2-1=1
r1
this
4
this^.a
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
9
16 end;
10.
Процедураobxod
adr [1]= адрес 4
adr [2]= адрес 2
no= 1
r1
this
4
this^.r
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
10
16 end;
11.
Процедураobxod
this
4
. 2
.
2
.
adr [1]= адрес 4
adr [2]= адрес 2
no= 1
r1
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
11
16 end;
12.
Процедураobxod
adr [1]= адрес 4
no= 1+1=2
adr [2]= адрес 2
r1
this
4
. 2
7
this^.l
.
2
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
12
16 end;
13.
Процедураobxod
.
this
4
. 2
.
2
.
adr [1]= адрес 4
no= 2
adr [2]= адрес 2
r1
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
13
16 end;
14.
Процедураobxod
adr [1]= адрес 4
no= 2
adr [2]= адрес 2
no= 2-1=1
r1
this
4
. 2
7
this^.a
.
2
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
14
16 end;
15.
Процедураobxod
this
4
. 2
.
2
. this^.r
adr [1]= адрес 4
adr [2]= адрес 2
no= 1
r1
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
15
16 end;
16.
Процедураobxod
.
this
4
. 2
.
2
.
adr [1]= адрес 4
adr [2]= адрес 2
no= 1
r1
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
16
16 end;
17.
Процедураobxod
adr [1]= адрес 4
no= 1-1=0
r1
this^.a
this
4
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
17
16 end;
18.
Процедураobxod
adr [1]:= адрес 4
no= 1-1=0
r1
this^.r
this
4
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
18
16 end;
19.
Процедураobxod
no= 0
r1
this
4
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
19
16 end;
20.
Процедураobxod
no= 0+1=1
adr [1]= адрес 7
r1
this
4
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
20
16 end;
21.
Процедураobxod
no=1
adr [1]= адрес 7
r1
4
. 2
.
2
.
this^.l
this
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
21
16 end;
22.
Процедураobxod
adr [1]= адрес 7
no=1+1=2
adr [2]= адрес 6
r1
4
. 2
.
2
.
this
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
22
16 end;
23.
Процедураobxod
adr [1]= адрес 7
no=1+1=2
adr [2]= адрес 6
r1
4
. 2
this
7
this^.l
.
2
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
23
16 end;
24.
Процедураobxod
adr [1]= адрес 7
no=2
adr [2]= адрес 6
r1
4
. 2
.
2
.
this
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
7
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
24
16 end;
25.
Процедураobxod
adr [1]= адрес 7
no=2
adr [2]= адрес 6
no=2-1=1
r1
4
. 2
this
7
this^.a
.
2
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
25
16 end;
26.
Процедураobxod
adr [1]= адрес 7
adr [2]= адрес 6
no=1
r1
4
. 2
this
7
this^.r
.
2
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
26
16 end;
27.
Процедураobxod
adr [1]= адрес 7
adr [2]= адрес 6
no=1
r1
4
. 2
.
2
.
this
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
7
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
27
16 end;
28.
Процедураobxod
adr [1]= адрес 7
no=1-1=0
r1
4
this^.a
. 2
.
2
.
this
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
28
16 end;
29.
Процедураobxod
no=0
r1
this
4
this^.r
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
29
16 end;
30.
Процедураobxod
no=0
r1
this
4
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
30
16 end;
31.
Процедураobxod
no=0+1=1
adr [1]= адрес 8
r1
this
4
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
31
16 end;
32.
Процедураobxod
no=1
adr [1]= адрес 8
r1
this
4
. 2
7
this^.l
.
2
.
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
32
16 end;
33.
Процедураobxod
no=1
adr [1]= адрес 8
r1
this
4
.
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
33
16 end;
34.
Процедураobxod
no=1
adr [1]= адрес 8
no=1-1=0
r1
this
4
. 2
.
2
.
7
. 6
.
.
8
.
this^.a
9
else
begin
3 while (this <> nil) or (no <> 0 ) do begin
10
this:=adr [no];
4
if this <>nil then begin
11
no:=no-1;
5
no:= no + 1;
6
adr [no]:= this;
12
Memo1.Lines.Add(inttostr(this^.a));
7
this:= this^.l
13
this:=this^.r
8
end
(* then *)
14
end
(* else *)
15
end
(* while *)
34
16 end;
35.
Процедураobxod
no=0
r1
this
4
. 2
.
2
.
7
. 6
.
.
8
.
this^.r
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
35
16 end;
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
36.
Процедураobxod
no=0
r1
this
4
.
. 2
.
2
.
7
. 6
3 while (this <> nil) or (no <> 0 ) do begin 9
10
4
if this <>nil then begin
11
5
no:= no + 1;
6
adr [no]:= this;
12
7
this:= this^.l
13
8
end
(* then *)
14
.
.
8
.
else begin
this:=adr [no];
no:=no-1;
Memo1.Lines.Add(inttostr(this^.a));
this:=this^.r
end
(* else *)
15
end
(* while *)
36
16 end;
37.
ПримерНайти адрес узла дерева, содержащего заданное число, если же такового
узла нет, то вставить его в дерево и указать адрес этого узла (дерево
построено в предыдущем примере).
Для решения задачи используется функция poiskvstavka, имеющая два
формальных параметра:
r1 - дерево;
n1- заданное число
Результатом функции является адрес узла дерева, содержащего заданное
число n1.
function poiskvstavka (r1: point; n1: integer): point;
var
this, predthis: point;
this – вспомогательная переменная, использующаяся для поиска узла в
дереве
predthis – вспомогательная переменная, которая содержит адрес узла, к
которому будет привязан новый узел (если узла с таким числом n1 в
дереве не нашлось)
37
38.
begin1 this:= r1;
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin (*найден узел с данным значением *)
8
poiskvstavka:=this;
9
exit (*выход из функции при удачном поиске, т.е. когда дерево содержит узел с
данным числом *)
10
end;
11 end;
(* while *)
12 new (this);
13 with this^ do begin
14
a:= n1;
15
l:= nil;
16
r:=nil;
17 end;
(* with *)
18 if n1 < predthis^.a then
19
predthis^ .l:= this
20 else predthis^.r:= this;
21 poiskvstavka := this
22 end;
38
39.
Функцияpoiskvstavka
predthis
this
4
. 2
.
2
.
n1=5
r1
7
. 6
1 this:= r1;
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
.
.
8
.
39
40.
Функцияpoiskvstavka
n1=5
r1
this^.r
predthis
this
4
this^.a
. 2
.
2
.
7
. 6
1 this:= r1;
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
.
.
8
.
40
41.
Функцияpoiskvstavka
predthis
this
4
. 2
.
2
. 1 this:= r1;
n1=5
r1
7
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
8
.
41
42.
Функцияpoiskvstavka
predthis
this
4
. 2
.
2
.
n1=5
r1
7
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
8
.
42
43.
Функцияpoiskvstavka
n1=5
r1
4
predthis
this^.a
. 2
this^.l
7
this
.
2
.
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
8
.
43
44.
Функцияpoiskvstavka
n1=5
r1
4
predthis
this^.a
. 2
this^.l
7
this
.
2
.
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
8
.
44
45.
Функцияpoiskvstavka
n1=5
r1
4
predthis
. 2
.
2
.
7
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
8
.
this
45
46.
Функцияpoiskvstavka
n1=5
r1
4
predthis
. 2
.
2
.
7
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
8
.
this
46
47.
Функцияpoiskvstavka
n1=5
r1
4
predthis
. 2
7
this^.a
.
2
.
this^.l
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
8
.
this
47
48.
Функцияpoiskvstavka
n1=5
r1
4
predthis
. 2
.
2
.
7
. 6
.
2 while this <> nil do begin
3
predthis:= this;
4
if n1 < this^ .a then this:= this^.l
5
else if n1 > this^.a then
6
this:=this^.r
7
else begin
8
poiskvstavka:=this;
9
exit
10
end;
11
end;
.
.
8
.
this
48
49.
Функцияpoiskvstavka
r1
n1=5
4
predthis
. 2
12
13
14
15
16
17
18
19
20
21
new (this);
with this^ do begin
a:= n1;
l:= nil;
r:=nil;
end;
(* with *)
if n1 < predthis^.a then
predthis^ .l:= this
else predthis^.r:= this;
poiskvstavka := this
7
this
.
2
.
this^.l
. 6
.
5
.
.
8
.
. this^.r
this^.a
49
50.
Функцияpoiskvstavka
r1
n1=5
4
predthis
. 2
2
new (this);
with this^ do begin
a:= n1;
l:= nil;
r:=nil;
end;
(* with *)
if n1 < predthis^.a then
predthis^ .l:= this
else predthis^.r:= this;
poiskvstavka := this
7
this
.
12
13
14
15
16
17
18
19
20
21
predthis^.l
.
. 6
.
.
8
.
predthis^.a
this^.l
.
5
. this^.r
this^.a
50
51.
Функцияpoiskvstavka
r1
n1=5
4
predthis
. 2
2
new (this);
with this^ do begin
a:= n1;
l:= nil;
r:=nil;
end;
(* with *)
if n1 < predthis^.a then
predthis^ .l:= this
else predthis^.r:= this;
poiskvstavka := this
7
this
.
12
13
14
15
16
17
18
19
20
21
predthis^.l
.
6
.
.
8
.
predthis^.a
this^.l
.
5
. this^.r
this^.a
51