严蔚敏数据结构课件第六章.ppt

Int Depth(CSTree T) { If (T==NULL) return 0; Else{ D1 = Depth(T-firstchild); D2 = Depth(T-nextsibling); Return Max{d1+1,d2} int TreeDepth( CTree T ) { // T 是树的孩子链表存储结构, // 返回该树的深度 if ( T.n == 0) return 0; else return Depth( T, T.r ); } // TreeDepth 一、求树的深度的算法: int Depth( CTree T, int root ){ max = 0; p = T.nodes[root].firstchild; while ( p ) { h = Depth( T, p-child ); if ( h max ) max = h; p = p-nextchild; }//while return max+1; } 二、输出树中所有从根到叶子的路径的算法: A B C D E F G

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档