This presentation is the property of its rightful owner.
Sponsored Links
1 / 190

教学要求: PowerPoint PPT Presentation


  • 101 Views
  • Uploaded on
  • Presentation posted in: General

教学要求: 掌握树的定义及基本术语,掌握二叉树的定义、性质和存储结构,熟练掌握二叉树的遍历方法及其实现和线索二叉树的构造,掌握树,森林和二叉树之间相互转换的方法,掌握哈夫曼树的定义和哈夫曼算法,了解哈夫曼编码的方法。 教学重点与难点: 二叉树的存储结构,二叉树的遍历及线索二叉树的构造,树、森林和二叉树之间的相互转换,哈夫曼树的定义和哈夫曼算法。. 第六章 树和二叉树. 6.1 树的定义与基本术语 6.2 二叉树 6.3 二叉树的遍历与线索化 6.4 树、森林和二叉树的关系 6.5 哈夫曼树及其应用 6.6 总结与提高.

Download Presentation

教学要求:

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


3520378


3520378

  • 6.1

  • 6.2

  • 6.3

  • 6.4

  • 6.5

  • 6.6


3520378

6.1

1

2

3

4


3520378

6.1

1

nn0Tn=0n>0

(1) root

(2) n-1mm0T1T2T3TmTiroot


3520378

A

B

C

D

E

F

G

H

I

J

K

L

M

6.1


3520378

A

B

C

D

A

B

C

D

2

1

2 6.2

3

4 6.3

(A(B(D),C))

6.2


3520378

3.

0

0

12


3520378

TTi

mm0


3520378

BCA

ABC

HIJ

6.1EGH


3520378

KABE

DHIJM


3520378

A

B

C

D

E

F

G

H

I

J

K

L

M

KLFGMIJ

A3

B2

M0

ID

LE

ABCD

BEF

3

4

BCD

KL

A1

M4

FG

AFG


3520378

F

root

A

(forest)

B

C

D

mm0

E

F

G

H

I

J

K

L

M

Tree = rootF

root

F


3520378

4.

D

RDDRR={H}H

(1) DrootH

(2) rootDH


3520378

(1)InitTreeTree Tree

(2) DestoryTreeTree Tree

(3) CreateTreeTree Tree

(4) TreeEmptyTree TreeTRUEFALSE

(5) RootTree Tree


3520378

(6) ParentTreex TreexTreex

(7) FirstChildTreex TreexTreex

(8) NextSiblingTreex TreexTreexx


3520378

:

(9) InsertChildTreepChild TreepTreeChildTreeChildTreep

(10) DeleteChildTreepi TreepTree1iddpTreepi

(11) TraverseTreeTreeVisit TreeVisitTreeVisitVisit


3520378

6.2

  • 6.2.1

  • 6.2.2

  • 6.2.3


3520378

6.2.1

Binary Tree

12

2

(d)

(e)

(b)

(a)

(c)


3520378

A

B

E

C

F

G

D

H

K


3520378

  • Initiatebtbt

  • (2) Create(bt)bt

  • (3) Destorybt bt

  • (4) Emptybt btTRUEFALSE

  • (5) Root(bt) btbt

  • (6) Parentbtxbtxxbtx


3520378

(7) LeftChildbtxxxbt

(8) RightChildbtxxxbt

(9) Traversebt:

(10) Clearbtbt


3520378

6.2.2

1i2i-1(i1)

i=12i-1=20=1

i=kk2k-1

i=k+1

2k+1k222k-1=2(k+1)-1


3520378

k

k

i= 2i-1= 2k-1

i=1

i=1

2k2k-1k1

kk


3520378

3Tn02n2n0= n2+1

nn112

n= n0+ n1+n2

Bn=B+1

12B=n1+2n2

n=B+1=n1+2n2+1

n= n0+ n1+n2n0+ n1+n2=n1+2n2+1n0= n2+1


3520378

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

k2k-1


3520378

1

2

3

4

5

6

7

8

9

10

11

12

13

14

kn1~n1~n


3520378

4n2n+1

nk2k-1 2k-1-1

k 2k-1

2k-1 - 1 < n 2k- 12k- 1 n< 2k

k -1 log2n < k

kk -1 =log2n k= 2n+1


3520378

5n1i

(1)i = 1, i

i >1, i i /2

(2)2*i > n, i

2*in, i 2*i

(3) 2*i+1> n ,i

2*i+1n, i2* i+1

(2)(3)


3520378

1n?

log2n + 1

n(n)

2102

n0=n2+1 n2=9


3520378

3.ni(1in)________________________

4. k( ).

A2k-1 B.2K+1 C.2K-1 D. 2k-1

5.ADEGHIJ_____________________________

6.________________


3520378

6.2.3


3520378

A

B

C

D

E

F

G

H

I

J

K

L

1.


3520378

A

B

C

D


3520378

A

A

B

C

B

C

D

E

F

D

E

F

G

G

2.

T


3520378

C

typedef struct Node

{DataType data;

strct Node * LChild;

struct Node * RChild;

}BiTNode, *BiTree;

n2nn1


3520378

B=n-1n-12n-(n-1)=n+1

Parent

LChild

Data

Parent

RChild


3520378

A

A

C

B

C

B

D

E

D

E

lchild data parent rchild


3520378

6.3

  • 6.3.1

  • 6.3.2

  • 6.3.3

  • 6.3.4

  • 6.3.5


3520378

LChild

Data

RChild

Data

LChild

LChild

RChild

6.3

6.3.1


3520378

LDR

  • (DLR)

  • (DRL)

  • (LDR)

  • (LRD)

  • (RDL)

  • (RLD)


3520378

DLR LDR LRDDLRLDRLRD


3520378

1DLR


3520378

D L R

A

D L R

D L R

C

B

A

D

D L R

>

>

>

B

C

>

>

D

:

A B D C


3520378

2LDR


3520378

A

C

B

D

B

L D R

L D R

>

>

>

A

C

L D R

>

>

D

:

L D R

B D A C


3520378


3520378

A

B

C

D

E

F

G

D B E A F C G

(DBEAFCG)


3520378

3LRD


3520378

A

C

B

D

L R D

L R D

B

L R D

>

>

>

A

C

>

>

D

:

L R D

D B C A


3520378

A

B

C

D

E

H

F

G

ABDFGCEH

BFDGACEH

FGDBHECA


3520378

-

+

/

a

*

f

e

b

-

c

d

-

+

a

*

b

-

c

d

/

e

f

a

+

b

*

c

-

d

-

e

/

f

a

b

c

d

-

*

+

e

f

/

-

-

+

/

a

*

e

f

b

-

c

d


3520378

1)

void PreOrder(BiTree root)

/*, root()*/

{if (root!=NULL)

{Visit(root ->data); /**/

PreOrder(root ->LChild); /**/

PreOrder(root ->RChild); /**/

}

}


3520378

2)

void InOrder(BiTree root)

/*, root()*/

{if (root!=NULL)

{

InOrder(root ->LChild); /**/

Visit(root ->data); /**/

InOrder(root ->RChild); /**/

}

}


3520378

3)

void PostOrder(BiTree root)

/* root()*/

{if(root!=NULL)

{

PostOrder(root ->LChild); /**/

PostOrder(root ->RChild); /**

Visit(root ->data); /**/

}

}


3520378

B

A

D

B

C

D

E


3520378

A

B

C

>

T

D

T

B

T

D

T

printf(B);

>

A

T

printf(D);

pre(T L);

printf(A);

pre(T L);

pre(T R);

pre(T L);

>

pre(T R);

T

Pre( T )

pre(T R);

T

C

>

T

printf(C);

pre(T L);

>

pre(T R);

T

void Preorder (BiTree T,

void( *visit)(TElemType& e))

{ if (T) {

visit(T->data);

Preorder(T->lchild, visit);

Preorder(T->rchild, visit);

}

}

A

B

C

D

A B D C


3520378

1.1215

2. A Tree is represented as

A(B(CD)E(F(G)H(I(JK)L(MNO))))

Please draw the tree


3520378

3.( )

4. A.

B.C.

D.


3520378

6.3.2

1.

void PreOrder(BiTree root)

/* , root */

{if (root!=NULL)

{printf (root ->data); /* */

PreOrder(root ->LChild); /* */

PreOrder(root ->RChild); /* */

}

}


3520378

2.


3520378

void PreOrder(BiTree root)

/* , root */

{if (root!=NULL)

{if (root ->LChild==NULL && root ->RChild==NULL)

printf (root ->data); /* */

PreOrder(root ->LChild); /* */

PreOrder(root ->RChild); /* */

}

}


3520378

3.


3520378

/* LeafCount,0 */

void leaf(BiTree root)

{if(root!=NULL)

{leaf(root->LChild);leaf(root->RChild);

if (root ->LChild==NULL && root ->RChild==NULL)

LeafCount++;

}

}


3520378

3.

01


3520378

int leaf(BiTree root)

{

int LeafCount;

if(root==NULL)

LeafCount =0;

else if ((root->LChild==NULL)&&(root->RChild==NULL))

LeafCount =1;

else /* */

LeafCount =leaf(root->LChild)+leaf(root->RChild);

return LeafCount;

}


3520378

4.

.


3520378

void CreateBiTree(BiTree *bt)

{ char ch;

ch=getchar();

if(ch=='.') *bt=NULL;

else

{*bt=(BiTree)malloc(sizeof(BiTNode));

(*bt)->data=ch;

CreateBiTree(&((*bt)->LChild));

CreateBiTree(&((*bt)->RChild));

}

}


3520378

5.

bt:

bt0

bt1

bt

High=max(hl+hr)+1

hl

hr


3520378

bt

lbt0

lbt1


3520378

int PostTreeDepth(BiTree bt) /* bt */

{ int hl, hr, max;

if(bt!=NULL)

{ hl=PostTreeDepth(bt->LChild); /* */

hr=PostTreeDepth(bt->RChild); /* */

max=hl>hr?hl:hr; /* */

return(max+1); /* */

}

else return(0); /* 0 */

}


3520378

1hh+1


3520378

void PreTreeDepth(BiTeee bt, int h)

/* bthbt1*/

/*depth0 */

{if(bt!=NULL)

{if(h>depth) depth = h; /*depthdepth*/

PreTreeDepth(bt->Lchild, h+1); /* */

PreTreeDepth(bt->Rchild, h+1); /* */

}

}


3520378

C

A

F

B

C

A

E

D

D

E

B

F

6.

900RDL


3520378

1906.15CFEADBRDL

21


3520378

void PrintTree(BiTree bt, int nLayer) /* */

{

if(bt = =NULL) return;

PrintTree(bt ->RChild, nLayer+1);

PrintTree(bt ->LChild , nLayer+1);

}

for(int i=0; i<nLayer; i++)

printf( );

printf(%c\n, bt ->data); /**/


3520378

6.3.3

1.


3520378

1

2

3


3520378

/*s[m] top*/

void inorder(BiTree root) /* root */

{top=0; p=root;

do{while(p!=NULL)

{ if (top>m) return;

top=top+1; s[top]=p; p=p->LChild

}; /* */

if(top!=0)

{ p=s[top];

top=top-1;

Visit(p->data); /* */

p=p->RChild; } /* */

}

} while(p!=NULL || top!=0)

}


3520378

(1)

(2)


3520378

void InOrderBiTree root/* */

{ InitStack (&S);

p=root;

while(p!=NULL || !IsEmpty(S))

{

if (p!=NULL) /* */

{ Push(&S,p);

p=p->LChild;

}

else { /**/

Pop(&S,&p); Visit(p->data);

p=p->RChild;

}

}

}


3520378

2.

(1)

(2)

(3)


3520378

void PostOrderBiTree root

{BiTNode * p,*qBiTree s[Stack_Size];int top=0;q=NULL; p=root;

while(p!=NULL || top!=0)

{while(p!=NULL)

{ top=++;

if(top>=Stack_Size)

OverFlow( ); /**/

s[top]=p; p=p->LChild; } /**/

if(top>0)

{p=s[top];

if((p->RChild==NULL) ||(p->RChild==q))/* */

{ visit(p->data); /* * /

q=p; /* q */

top--; p=NULL;

}

elsep=p->RChild;

}

}

}


3520378

A

B

C

D

E

F

G

H

()

1


3520378

()

  • (1)..

  • (2)..


3520378

6.3.4

1.


3520378

n2nn-1n+1n+1

LChildLChildRChildRChild


3520378

0 LChild

1 LChild

Ltag=

0 RChild

1 RChild

Rtag=


3520378


Lchild ltag 0 rtag 1

0 1

0 0

0 0

1 c 1

c

1 b 1

1 a 1

a

b

lchildltag=0rtag=1


3520378

A

A

B

C

B

C

D

E

F

D

E

F

G

H

NULL

G

H

(a)

(b)


3520378

A

B

C

D

E

F

G

H

(a)

A

B

C

D

E

F

G

H

NULL

NULL

c


3520378

A

B

C

D

E

F

G

H

(a)

A

B

C

D

E

F

G

H

NULL

d


3520378

2.

1

2

3pre

rootpre

preroot

rootpre


3520378

void Inthread(BiTree root)

/* rootpreNULL* /

{ if (root!=NULL)

{ Inthread(root->LChild); /* */

if (root->LChild==NULL)

{root->Ltag=1; root->LChile=pre; } / * */

if (pre!=NULL&& pre->RChild==NULL) /* */

{ pre-> RChild=root; pre->Rtag=1; }

pre=root/ /**/

Inthread(root->RChild); /**/

}

}


3520378

3.

(1)

BiTNode * InPre(BiTNode * p)

/* p, pre */

{ if(p->Ltag==1) pre= p->LChild; /**/

else

{ /* p */

for(q= p->LChild;q->Rtag==0;q=q->RChild);

pre=q;

}

return(pre);

}


3520378

(2)

pp->Rtag=1p->RChildpp->Rtag=0pp

BiTNode * InNext(BiTNode * p)

/*pNext*/

{ if (p->Rtag==1) Next= p-> RChild; /**/

else { /*p*/

for(q= p->RChild; q->Ltag==0 ;q=q->LChild ); /**/

Next=q;

}

return(Next)

}


3520378

4.

(1)

BiTNode * InFirst(BiTree Bt)

{

BiTNode *p=Bt;

If(!p) return (NULL);

while(p->LTag==0) p=p->Lchild;

return p;

}


3520378

(2)

void TInOrder(BiTree Bt)

{

BITNode *p;

P=InFirst(Bt);

While(p)

{

Visit(p);

p = InNext(p)

}

}


3520378

5.


3520378

1

InsNode(BiTNode * p, BiTNode * r)rp


3520378

p

p

r

r

prprprrprp


3520378

p

r

p

p

r

r

pprprrpppr


3520378

void InsNode(BiTNode * p , BiTNode * r)

{ if (p->Rtag==1) /* p */

{ r->RChild=p->RChild; /* pr */

r->Rtag=1;

p->RChild=r; /* rp */

r->LChild=p; /* pr */

r->Ltag=1;

}

else /* p */

{ s=p->RChild;

while(s->Ltag==0)

s=s->LChild; /* p */

r->RChild=p->RChild; /* pr */

r->Rtag=0;

r->LChild=p; /* pr */

r->Ltag=1;

p->RChild=r; /* rp */

s->LChild=r; /* rp */

}

}


3520378

r

p

p

r

(b)

(a) )

2

r


3520378

6.3.5

DLRDLDRDDD


3520378

18 14 7 3 11 22 35 27

3 7 11 14 18 22 27 35

18371114,22273514731122 35 271818


3520378

18

22

14

35

7

27

11

3


3520378

ACIKNHLMICNKALMH

(


3520378

A

A

C

ICNK

LMH

H

I

C

K

L

H

N

I

NK

M

LM

L

K

N

M

ACIKNHLMICNKALMH


3520378

DCBGEAHFIJK

DCEGBFHKJIA


3520378

1( )

A. EGFACDB

B. EAGCFBD

C. EACBDGF

D. EGACDFB

2( )

A. ABCDEGF

B. EAGCFBD

C. EACBDGF

D. DCAFGE


3520378

3( )

A. EGFACDB

B. EACBDGF

C. EAGCFBD

D. EGACDFB

479 2 30 + - 4 2 / *__________3+X*Y-2Y/3_______________________________


3520378

The following traversals unambiguously define a binary tree. Please draw the tree.

Postorder: CBEHGIFDA

Inorder: BCAEDGHFI


3520378

bn= C

1

n

n+1

2n

  • n

  • Find all binay tree whose nodes appear

  • in exactly all the same sequence in both

  • Preorder and inorder

empty)

(root)

(right-skewed binary tree)


3520378

b.Preorder and postorder

empty)

(root)

c.Inorder and postorder

empty)

(root)

(left-skewed binary tree)


3520378

2

12


3520378

2EBADCFHGIKJABCDEFGHIJK


3520378

6.4

6.4.1

6.4.2

6.4.3


3520378

6.4.1

1.

2.

3.


3520378

Data

Parent

1

1

-1

0

2

0

1

2

3

3

0

2

4

1

3

4

5

1

5

6

7

4

6

1

5

1.


3520378


3520378

#define MAX 100

typedef struct TNode

{

DataType data;

int parent;

}TNode;

typedef struct

{

TNode tree[MAX];

int nodenum; /**/

}ParentTree;


3520378

2. nnnn

r


3520378

typedef struct ChildNode /* */

{int Child; /* */

struct ChildNode * next; /* */

}ChildNode;

typedef struct /* */

{DataType data; /* */

ChildNode * FirstChild ; /* */

}DataNode;

typedef struct /* */

{

DataNode nodes[MAX]; /* */

int root,num;

/* */

} ChildTree;


3520378

3.


3520378

typedef struct CSNode

{

DataType data; /**/

Struct CSNode *FirstChild, *Nextsibling;

/*,*/

}CSNode, *CSTree;


3520378

A

B

C

D

E

F

G

H

6.4.2

1.


3520378

H

B

A

F

H

E

G

C

B

D

A

F

D

E

G

C

B

D

A

F

H

E

G

C


3520378


3520378

2.

1

2


3520378

A

(b)

G

H

J

I

D

F

A

A

B

E

B

C

D

E

F

G

H

I

J

C

B

E

F

C

G

D

H

I

J

(a)

(c)


3520378

FF={T1T2,TN}BF

1N=0BF

2N>0BFT1BFB{T11T1m}{T11T1m}T1BFB{T2TN}


3520378

BT2

E

F

F={T1 T2 T3}

G

T2

T3

T1

A

E

H

I

F

C

D

B

J

A

E

B

BT3

BT1

G

G

A

F

C

H

H

B

I

I

C

D

J

D

J


3520378

A

B

E

C

F

G

D

H

I

J

3.


3520378

D

F

D

A

B

C

E

F

G

H

J

D

B

I

A

A

C

E

I

H

J

F

E

C

B

G

G

H

I

J

1

2

312


3520378

BTBLBRBBFBnT1,T2, ,Tn

1BFBn0

2BFBT1BTT1BLFL={T11,,T1m}BRFBF(R){ T2, T3, ,Tn}


3520378

1

2

3

4

5

6

7

8

2


3520378

1

9

10

2

12

5

13

6

7

14

15

8

3

11

3

4

T1 T2 T3 T4


3520378

A

B

C

D

E

F

G

H

6.4.3

1.

1

ABECFHGD


3520378

(2)

EBHFGCDA


3520378

2.

void RootFirst(CSTree root)

{

if (root!=NULL)

{ Visit(root ->data); /* */

p= root-> FirstChild;

while (p!=NULL)

{ RootFirst( p ); /* p */

p = p -> Nextsibling;

}

}

}


3520378

void RootFirst(CSTree root)

{

if (root!=NULL)

{

Visit (root ->data); /**/

RootFirst (root->FirstChild); /**/

RootFirst (root->Nextsibling); /**/

}

}


3520378

3.

(1)


3520378

(2)


3520378

(3)


3520378

6.5

6.5.1

6.5.2


3520378

1.


3520378

n

WPL=wili

i=1

n wiilii


3520378

(b)46

A

D

C

D

B

B

A

C

7

C

B

D

A

5

4

7

2

5

2

2

4

4

7

5

(c)35

(a)36

WPL(a)=7252224236

WPL(b)=4273532146

WPL(c)=7152234335


3520378

{2,3,4,7}

2 3 4 7

(a) WPL=2223+24+27=32


3520378

2

3

7

4

(b) WPL=1223+34+37=41


3520378

7

4

2

3

(c) WPL=1724+33+32=30


3520378

2.

nWPL


3520378

(1)n{w1,w2, ,wn}nnF={T1,T2, ,Tn}Ti (1in)wi

(2)F

(3)FF

(4)23


3520378

{W1....Wn}nnFF={T1....Tn}T1T2T=T1+T2F


3520378

3.

(1)

,1n2n12n1

:

01


3520378

data

parent

LChild

RChild

1

A

0

2

3

A

2

B

1

0

0

B

C

3

C

1

4

5

D

E

4

D

3

0

0

5

E

3

0

0


3520378

(2)

#define N 20 /* */

#define M 2*N-1 /* */

typedef struct

{

int weight ; /* */

int parent ; /* */

int LChild ; /* */

int RChild ; /* */

} HTNode, HuffmanTree[M+1]; /* HuffmanTree0 */


3520378

4.

void CrtHuffmanTree(HuffmanTree ht, int w[ ], int n)

{ /*ht[M+1]w[ ]n*/

for(i=1;i<=n;i++) ht[i] ={ w[i],0,0,0}; /* 1 ~ n*/

m=2*n-1;

for(i=n+1;i<=m;i++) ht[i] ={0,0,0,0};

/*1*/

for(i=n+1; i<=m; i++) /**/

{

select(ht, i-1, s1, s2); /* ht[1] ~ ht[i-1] parent0

weights1s2 */

ht [i].weight= ht [s1].weight+ ht [s2].weight;

ht [s1].parent=i;ht [s2].parent=i;

ht [i].LChild=s1;ht [i].RChild=s2;

} /**/

}


3520378

0

1

state,seat,act,tea,cat,set,a,eat

s t a e c

3 8 7 5 2


3520378


6 5 2

Huffman

1

6.5.2


3520378

ABACCDA 2

1

A B C D

00 01 10 11

00010010101100 14

2

.


3520378

2

A B C D

0 00 1 01

000011010 9

BBCCACAAAAACCDA


3520378

3

A B C D

0 110 10 111

0110010101110 13


6 5 21

nWi ,

Li (i=1,2,n)

Wi Li

Wi Li

Huffman01

HuffmanHuffman

6.5.2


3520378

(1)010010101001100101001010

(2)n01


3520378

2

: 7


3520378

1.00

0.06

0.60

0.30

0.15

0.09

0.40

0.15

0.03

0.05

0.03

0.04

0.30

n

I4

I7

I2

I6

I1

I3

I5

pili

i=1

01


3520378

3.

typedef char * HuffmanCode[N+1]; /* */


3520378

void CrtHuffmanCode(HuffmanTree ht, HuffmanCode hc, int n)

/**/

{ char *cd;

hc=(HuffmanCode *)malloc((n+1)*sizeof(char *));

/*n*/

cd=(char * )malloc(n * sizeof(char ));

/**/

cd[n-1]\0 /**/

for(i=1;i<=n;i++) /*n*/

{

start=n-1; /**/

c=i; p=ht[i].parent; /* */


3520378

while(p!=0)

{ --start;

if(ht[p].LChild==c) cd[start]=0; /*0*/

else cd[start]=1; /*1*/

c=p; p=ht[p].parent; /* */

}

hc [i]=(char *)malloc((n-start)*sizeof(char));

/*i*/

strcpy(hc[i], &cd[start]); /*hc[i]*/

}

free(cd);

}


3520378

  • *

  • *

  • *

  • *

  • *

  • *


3520378

A

B

C

D

E

F

G

H

I

J

K

L

M

1


3520378

1

2

3

4

5

15

8

9

10

11

2

1i2i-1(i1)

2k2k-1k1

3Tn02n2n0= n2+1


3520378

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

3


3520378

4

5


3520378

6

7

8

9

1

2

3

4


3520378

3

Q,


3520378

1Q;

2bt

3btQ

4


3520378

int LayerOrder(BiTree bt)

/*bt*/

{ SeqQueue * Q;

BiTree p;

InitQueueQ /*Q*/

if(bt= =NULL) return ERROR; /*bt*/

EnterQueue(Q, bt); /*btbt*/

while (!IsEmpty(Q)) /**/

{

DeleteQueue(Q, &p); /* */

visit(p->data);

if(p-> LChild ) EnterQueue(Q,p-> LChild) ; /*p*/

if(p-> RChild ) EnterQueue(Q,p-> RChild) ; /*p*/

} /*while*/

return OK;

} /* LayerOrder */


3520378

3

int LayerOrder(BiTree bt)

{Sequeue *Q; BiTree p; InitQueue(Q);

if (bt==NULL) return ERROR;

EnterQueue(Q,bt);

while (!IsEmpty(Q))

{ DeleteQueue(Q,&p);visit(p->Lchild)

if (p->Lchild) EnterQueue(Q,p->Lchild);

if (p->Rchild) EnterQueue(Q,p->Rchild);

}

return OK;

}


3520378

A

B

D

C

E

F

G

H

J

I

:

133

2


3520378

31000211001

321112n+1,1n2n+12n11n-12n


3520378

10005004992

11100150150021


3520378

1FM1M2M3F

AM1 BM1+M2 CM3 DM2+M3

2356911


3520378

WPL=112+62+92 +53 +24+34=87


3520378

( )1

( )2,

( )3

( )4Huffman

( )5


3520378

1

9

11

16

2

17

18

10

12

19

3

4

5

13

14

6

7

15

8

T1 T2 T3 T4

1


3520378

27a,b,c,d,e,f,g2781251547WPL


  • Login