Двоичное (бинарное) дерево
Процедура obxod
Процедура obxod
274.03K

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.

begin
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;
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
English     Русский Правила