C++ 如何用算法判断输入数据的先序次序构不成二叉树

问题遇到的现象和发生背景

当输入一些无规律的数据时无法输出相应结果

问题相关代码,请勿粘贴截图
#include<iostream>
using namespace std;
typedef struct BiNode{
    char data;
    struct BiNode *lchild,*rchild;
}BiNode,*BiTree;
void CreateBiTree(BiTree &T){
   char ch;
   cin>>ch;
   if(ch=='#')T=NULL;
   else{
          T=new BiNode;
          T->data=ch;
          CreateBiTree(T->lchild);
          CreateBiTree(T->rchild);
   } 
}
void InOrder(BiTree T){
    if(T){
        InOrder(T->lchild);
        cout<<T->data;
        InOrder(T->rchild);
    }
}
void PreOrder(BiTree T){
    if(T){
        cout<<T->data;
        PreOrder(T->lchild);
        PreOrder(T->rchild);
    }
}
void PostOrder(BiTree T){
    if(T){
        PostOrder(T->lchild);
        PostOrder(T->rchild);
        cout<<T->data;
    }
}
int CountLeaf(BiTree T){
    static int count=0;
    if(T){
        if((!T->lchild)&&(!T->rchild))
        count++;
        CountLeaf(T->lchild);
        CountLeaf(T->rchild);
    }
    return count;
} 
int Depth(BiTree T){
    int m,n;
    if(T==NULL)return 0;
    else{
        m=Depth(T->lchild);
        n=Depth(T->rchild);
        if(m>n)return (m+1);
        else return (n+1);
    }
}
int CountNode(BiTree T){
    if(T==NULL)return 0;
    else
    return CountNode(T->lchild)+CountNode(T->rchild)+1;
}
int main(){
    BiTree tree=NULL;
    CreateBiTree(tree);
    if(){
        PreOrder(tree);cout<<endl;
        InOrder(tree);cout<<endl;
        PostOrder(tree);cout<<endl;
        cout<<Depth(tree)<<endl;
        cout<<CountNode(tree)<<endl;
        cout<<CountLeaf(tree)<<endl;
    }else{
        cout<<"创建二叉树失败"<<endl; 
    }
    }

运行结果及报错内容

随机输入时什么的都输出不出来

我的解答思路和尝试过的方法
我想要达到的结果

当输入数据的先序次序构不成二叉树时输出创建二叉树失败。



无规律的数据指的是什么样的数据?
A B C D
还是能够建二叉树的啊
字母A 都能成为根节点。
你是想判断满二叉树,平衡二叉树,完全二叉树吧?