Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

.

5.
5.1

.
.
,
()
.

.
( ).
.
(
).
5.1. ,
, .
( )
( ),
.

5.1

. ,
( )
, .

.
: ,
, .
1

. -


( ) .
5.2.

(hyperlinks).

(a)

()
5.2
: ,
.
:
? (
: ,

)
.
.

:
1. ( )
2.
3. , ( )
.
4. ( )

. -

5.3

, ,
. ,
5.3. ,
.

(
- ).


.
,
.
.

5.2 :
.


. ,
.
,
.
, .
3

. -

,, .
.
, :
1. . , .
2. n T1, T2, ..., Tk n1, n2, , nk .
n
T1, T2, ..., Tk. n1, n2, , nk
n.
.
() .
,
.
:

:
1. ;
2. ( ) k 0
T1, T2, ..., Tk, .
T.

.
5.4 .

5.4.
A (root) .
{,,,}.
. ,
( ) .

. -


( 5.5).
. 0,
() . ( ) .

. ,

, 0.
. ,
( ).
( ),
().
.

5.5.
5.6, ,
.
, , , , . , , .
.
.

. -

5.6.
( ) ()
. , .
,
.
n1, n2, , nk ni ni+1, 1 i < n,
n1 nk. 5.6,
A : A, , , .
,
.
0.

B, B, B . 5.6 ,
, , , , .
.
. 5.6,
A, , .
()
. . 5.6
.
.
.
5.6, 4, 5 .
. 5.6,
5.

. .
6

. -

.
.

5.3

.
.


. ,
.
5.7.

5.7.

5.7.

. -

5.7 .
:
typedef int info_t;
typedef struct jazel
{
info_t info;
struct jazel *left;
struct jazel *right;
} node;

info_t .

.
( ).
( ).

.
,
. 5.8 ,
:

5.8.
: a b T a , b
, a b.

5.4

,
. ,
,
. .
.

.
8

. -

5.9 .
.
.

5.9.


.
,
.


.

5.5

,
( )
. 5.10
, ,
. 5.10,
45 5.10
5.10.

. -

5.10.

5.10.

5.10.
5.10

10

. -

. 5.11
.

5.11.


.

5.12.

5.12

11

. -


:
T1, ...,Tn ,
B(T1, ..., Tn)
:
B(T1, ..., Tn)
(i) n = 0;
(ii) (T1); B(T11,T12, ...,T1m)
T11, ..., T1m (T1); B(T2, ...,
Tn).

5.6

: , .
, ,
. ,
, .
K
T1 T2. :

K
1 ,
2 .

1 , K,
2 .

1 ,
2
.

( ).
,

. (
)
12

. -

. 5.13
.
: (a - b c)/(d + e f)

5.13.

:
: - a bc + d e f
:

a-bc/d+ef

: a b c - d e f + /

: prefix,
infix postfix
.

:
void inorder(nodep p)
{
if(p!=NULL)
{
inorder(p->left);
printf("%d\n",p->info);
inorder(p->right);
}
}

void preorder(nodep p)
{
if(p!=NULL)
{
printf("%d\n",p->info);
preorder(p->left);
preorder(p->right);
}
}

13

. -

void postorder(nodep p)
{
if(p!=NULL)
{
postorder(p->left);
postorder(p->right);
printf("%d\n",p->info);
}
}

5.7


/
.

.
, . 5.14
.
void vmetni_levo(nodep p, info_t x)
{
nodep q=NEW(node);
q->info=x;
q->left= p->left;
q->right=NULL;
p->left=q;
}

void vmetni_desno(nodep p, info_t x)


{
nodep q=NEW(node);
q->info=x;
q->right = p->right;
q->left=NULL;
p->right=q;
}

5.14. q
p
,
.
. ,
(
). , ,
.
,
.
14

. -

5.8

.

(treads).
.

. ,
.
,
.
.
5.15. ()
.

5.15

,
.
. (
).
.
(
)
( ),
.


( ).

. (INFO)
, (LLINK, RLINK)
15

. -

( LTAG RTAG LBIT RBIT).


RBIT 1 ,
0 .
typedef int info_t;
typedef struct jazel
{
info_t info;
struct jazel *left;
int lbit;
struct jazel *right;
int rbit;
} node;

5.16.
.

5.16
5.17.

, ,

.
.

5.17

16

You might also like