Home > database >  What a great god can help me to see why the code what the problem is that in addition to done to car
What a great god can help me to see why the code what the problem is that in addition to done to car

Time:09-27

# include "iostream. H" # include "stdlib. H" # include "stdio.h" typedef char ElemType;//define the type of binary tree node values for character const int MaxLength=10;//node number is less than 10 typedef struct BTNode {ElemType data; Struct lchild BTNode * and * rchild; } BTNode, * BiTree; Void CreateBiTree (BiTree & amp; T) {//according to the first sequence order input, constructing binary list according to binary tree T, empty Spaces said tree//if (T) return; char ch; ch=getchar();//cannot use cin to input, can't identify Spaces in cin, the if (ch==' ') T=NULL; The else {the if (! (T=(BTNode *) malloc (sizeof (BTNode)))) cout<" The malloc fail!" ; T - & gt; data=https://bbs.csdn.net/topics/ch; CreateBiTree (T -> lchild); CreateBiTree (T -> rchild); }} void PreOrderTraverse (BiTree T) {//sequence traversal first if (T) {cout data <'; PreOrderTraverse (T - & gt; Lchild); PreOrderTraverse (T - & gt; Rchild); }} void InOrderTraverse (BiTree T) {//sequence traversal of the if (T) {InOrderTraverse (T - & gt; Lchild); cout Data<"'; If (p - & gt; Lchild) {//left child is empty, not team Q (rear)=p - & gt; Lchild; Rear=(rear + 1) % MaxLength; } the if (p - & gt; Rchild) {//right child is empty, not team Q (rear)=p - & gt; Rchild; Rear=(rear + 1) % MaxLength; }}}//non recursive sequence first time calendar calculation method of void NRPreOrder BiTree (bt) {BiTree stack [MaxLength], p; int top; If (bt!!!!=NULL) {top=0; P=bt; While (p!=NULL | | top> {0) while (p!=NULL) {cout The data; Stack [top]=p; Top++; P=p - & gt; Lchild; } the if (top> 0 {top -; P=stack [top]; P=p - & gt; Rchild; }}}}//non recursive sequence through calendar calculation method in the void NRInOrder BiTree (bt) {BiTree stack [MaxLength], p; int top; If (bt!!!!=NULL) {top=0; P=bt; While (p!=NULL | | top> {0) while (p!=NULL) {stack [top]=p; Top++; P=p - & gt; Lchild; } the if (top> 0 {top -; P=stack [top]; cout The data; P=p - & gt; Rchild; }}}}//non recursive sequence through calendar calculation method after typedef struct {BiTree PTR. Int the tag; } stacknode; Void NRPostOrder BiTree (bt) {stacknode s [MaxLength], x; BiTree p=bt; int top; If (bt!!!!=NULL) {top=0; P=bt; Do {while (p!=NULL)//traverse left subtree {s [top]. PTR=p; S [top] tag=1;//tags for the left subtree top++; P=p - & gt; Lchild; } while (top> 0 & amp; & S [top 1] tag==2) {x=s [-- top]; P=x.p tr. cout The data;//tag to R, said right subtree access to complete, so the access to the root node} the if (top> [top 1 0) {s] tag=2;//traverse right subtree is p=s [top - 1]. PTR - & gt; Rchild; }} while (top> 0); }}//PostOrderUnrecvoid main () {BiTree T; T=NULL; Int the select;//cout<" Please input value of each node in a first order sequence expressed in space empty tree (input can be imported in succession) : "& lt; The select; The switch (select) {0 case: return; Case 1: cout<" Please input value of each node in a first order sequence expressed in space empty tree (input can be imported in succession) : "& lt;
  • Related