慕虎7371278
#include #include #include#define maxnode 100#define NULL 0typedef char DataType; /*设数据域类型为字符型*/typedef struct node{DataType data;struct node *lchild,*rchild; /*左右链域为指向结点结构的指针类型*/}bintnode; /*结点类型*/typedef bintnode *bintree; /*指向二叉树结点的指针类型*/void createbintree(bintree *T); /*构造二叉链表*/void Preorder(bintree T); /*先序*/void inorderout(bintree T); /*中序*/void Postorder(bintree T); /*后序*/void LevelOrder(bintree T); /*按层次遍历二叉树T*//*以加入结点的先序序列输入,构造二叉链表*/void createbintree(bintree *T){char ch;scanf("\n%c",&ch);if(ch=='0')*T=NULL;else{*T=(bintnode*)malloc(sizeof(bintnode));(*T)->data=ch;createbintree(&(*T)->lchild);createbintree(&(*T)->rchild);}}/*先序遍历二叉树T*/void Preorder(bintree T){if (T){cout<data; /*访问结点数据*/Preorder(T->lchild); /*先序遍历二叉树T的左子树*/Preorder(T->rchild); /*先序遍历二叉树T的右子树*/}}/*中序遍历二叉树T*/void inorderout(bintree T){if(T){inorderout(T->lchild); /*中序遍历二叉树T的左子树*/cout<data; /*访问结点数据*/inorderout(T->rchild); /*中序遍历二叉树T的右子树*/}}/*后序遍历二叉树T*/void Postorder(bintree T){if (T){Postorder(T->lchild); /*后序遍历二叉树T的左子树*/Postorder(T->rchild); /*后序遍历二叉树T的右子树*/cout<data; /*访问结点数据*/}}void LevelOrder(bintree bt){bintree queue[maxnode];int front,rear;if (bt==0)return;front=-1; /*队列初始化*/rear=0;queue[rear]=bt; /*根结点入队*/while(front!=rear){front++;cout<data; /*访问队首结点的数据域*/if(queue[front]->lchild!=NULL) /*将队首结点的左孩子结点入队列*/{rear++;queue[rear]=queue[front]->lchild;}//ifif(queue[front]->rchild!=NULL) /*将队首结点的右孩子结点入队列*/{rear++;queue[rear]=queue[front]->rchild;}//if}//while}//LevelOrdervoid main(){bintree T;char a,b;cout<>b;switch(b){case '1': cout<