Advertisement

比较由两个序列生成的二叉排序树是否相同

阅读量:

通过构建输入数字序列对应的二叉排序树,分别执行先序遍历与中序遍历操作(该过程可唯一确定一棵二叉树)。随后对比所得的先序遍历结果与中序遍历结果是否一致,若两者完全相符,则表明所构建的二叉搜索树为同一棵。

复制代码
 #include <iostream>

    
 #include <stdio.h>
    
 #include <stdlib.h>
    
 #include <string.h>///记得加上.h
    
  
    
 using namespace std;
    
  
    
  
    
 typedef struct BiNode
    
 {
    
     char data;
    
     struct BiNode *lchild,*rchild;
    
  
    
 }BiNode,*BiTree;
    
  
    
 void pre_order (BiTree T,char pre_array[],int &index)///先序遍历内部函数index是数组下标,因为递归时需要改变,
    
 {                                                    ///index必须使用引用型。
    
     if(T!=NULL)
    

全部评论 (0)

还没有任何评论哟~