#include
# define MaxQueueSize 20
Typedef char Data;
Typedef struct Node
{
Data sj.
Struct Node * rchild;
Struct Node * lchild;
} Tree;
Typedef struct
{
The Data queue [MaxQueueSize];
Int rear;//of the pointer
Int the front;//team head pointer
Int count;//counter
} SeqCQueue;
Void QueueInitiate (SeqCQueue * Q)
{
Q - & gt; Rear=0;
Q - & gt; The front=0;
Q - & gt; count=0;
}
Void QueueAppend (SeqCQueue * Q, Data x)
{
If (Q - & gt; The count & gt; 0 & amp; & Q - & gt; Rear==Q - & gt; Front)
{
Printf (" queue is full can't insert! \n");
//return 0;
}
The else
{
Q - & gt; The queue [Q - & gt; rear]=x;
Q - & gt; Rear=(Q - & gt; Rear + 1) % MaxQueueSize;
Q - & gt; count++;
//return 1;
}
}
Void QueueDelete (SeqCQueue * Q, Data * d)
{
If (Q - & gt; The count==0)
{
Printf (" the queue empty numerous elements according to the queue! \n");
//return 0;
}
The else
{
* d=Q - & gt; The queue/Q - & gt; front;
Q - & gt; The front=(Q - & gt; Front + 1) % MaxQueueSize;
Q - & gt; count--;
//return 1;
}
}
//initialize the established binary tree head node
Void Initiate * * root (Tree)
{
Tree * * root=() malloc (sizeof (Tree));
(* root) - & gt; Lchild=NULL;
(* root) - & gt; Rchild=NULL;
}
* InsertLeftNode Tree (Tree * curr, DataTree * InsertLeftNode (Tree * curr, Data x)
{
Tree * s * * t;
If (curr==NULL)
Return NULL;
T=curr - & gt; Lchild;//save referred to in the original curr node left subtree pointer
S=(Tree *) malloc (sizeof (Tree));
S - & gt; Sj=x;
S - & gt; Lchild=t;//left subtree of the newly inserted node for the original curr left subtree
S - & gt; Rchild=NULL;
Curr - & gt; Lchild=s;//left subtree of the new node for the curr
Return curr - & gt; Lchild;
}
Tree * InsertRightNode (Tree * curr, Data x)
{
Tree * s * * t;
If (curr==NULL) return NULL;
T=curr - & gt; Rchild;//save the original curr refers to the right child node tree pointer
S=(Tree *) malloc (sizeof (Tree));
S - & gt; Sj=x;
S - & gt; Rchild=t;//insert the new node's right child tree for the original curr right subtree
S - & gt; Lchild=NULL;
Curr - & gt; Rchild=s;//new nodes for the curr right subtree
Return curr - & gt; Rchild;
}
Int chanci (Tree, the Tree * SeqCQueue * q, Data * d)
{
If ((tree - & gt; Sj)==NULL)
{
return 0;
}
The else
{
//void QueueAppend (SeqCQueue * Q, Data x);
QueueAppend (q, tree - & gt; Sj);
//void QueueDelete (SeqCQueue * Q, Data * d);
QueueDelete (q, d);
Printf (" % c ", * d); Int temp1;
Temp1=chanci (tree - & gt; Lchild, q, d);
Int temp2;
Temp2=chanci (tree - & gt; Rchild, q, d);
Return 1 + temp1, temp2;
}
}
//the depth of the output tree T
Int deep * Tree (Tree)
{
If (tree==NULL | | tree - & gt; Sj==NULL)
{
return 0;
}
The else
{
Return 1 + deep (tree - & gt; Lchild);
}
}
//leaves
Int yezi * Tree (Tree)
{
If (tree==NULL | | tree - & gt; Sj==NULL)
{
return 1;
}
The else
{
Return 0 + yezi (tree - & gt; Yezi lchild) + (tree - & gt; Rchild);
}
}
Int noyezi * Tree (Tree)
{
If (tree - & gt; Sj=NULL)
{
return 0;
}
The else
{
Return 1 + yezi (tree - & gt; Yezi lchild) + (tree - & gt; Rchild);
}
}
Int main ()
{
//create a binary tree
Root Tree *, * p;
SeqCQueue * Q;
SeqCQueue Qdate;
Q=& amp; Qdate;
The Data d;
Void Initiate * * root (Tree);
Void QueueInitiate SeqCQueue * (Q);
QueueInitiate (Q);
Initiate (& amp; Root);
Root - & gt; Sj=' ';
P=InsertLeftNode (root, 'A');
P=InsertLeftNode (p, 'B');
InsertRightNode (p, 'E');
InsertRightNode (p - & gt; Rchild, 'K');
InsertLeftNode (p - & gt; Rchild, 'J');
P=InsertLeftNode (p, 'D');
InsertLeftNode (p, 'H');
P=InsertRightNode (p, 'I');
P=InsertRightNode (root - & gt; Lchild, 'C');
InsertLeftNode (p, 'F');
InsertRightNode (p, "G");
Printf (" % c \ n ", root - & gt; Lchild - & gt; Sj);
Printf (" % c \ n ", root - & gt; Lchild - & gt; Lchild - & gt; Sj);
//level traversal
Int chanci (Tree, the Tree * SeqCQueue * q, Data * d);
int n;
N=chanci (root - & gt; Lchild, Q, & amp; D);
Printf (" % d \ n ", n);
/*//the depth of the output tree T;
Int deep * Tree (Tree);
Int m;
M=deep (root - & gt; Lchild);
Printf (" % d \ n "deep, m);
//output nodes and leaves the leaves of the tree T
Int yezi * Tree (Tree);
Int noyezi * Tree (Tree);
Int y, no;
Y=yezi (root - & gt; Lchild);
Printf (" % d "leaves, y);
No=noyezi (root - & gt; Lchild);
Printf (" the leaf % d ", no); */
}
In the function chanci the tree - & gt; A nulltrp sj, does not solve, recursive failed to finish so the recursive