中序遍历

clip_image001

输入:Lson[8]={2,4,6,0,0,0,0,0}

Rson[8]={3,5,0,7,0,8,0,0}

此两个数组下标从1开始,下标表示树的节点

输出:number[8]

要求:对二叉树进行中序遍历,并根据遍历顺序为每个节点编号,并将编号存储在number数组里,打印输出

解:先定义一个全局变量count,初始值为1

注意:程序中的v表示二叉树

Procedure enorder(v)

Begin

if Lson(v)!=0 then enorder(Lson(v));

number[v]=count;

count++;

if Rson(v)!=0 then enorder(Rson(v);_

clip_image002

posted @ 2011-06-08 16:00  llzdev  阅读(307)  评论(0编辑  收藏  举报