该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
void TranslevelPrint(Bitree bt)
{
struct node
{
Bitree vec[MAXLEN]; //存放树结点
int layer[MAXLEN]; //结点所在的层
int locate[MAXLEN]; //打印结点的位置
int front,rear;
}q;
int i,j,k;
int nLocate;
j = 1;
k = 0;
q.front = 0;
q.rear = 0;
//printf(" ");
printf(" ");
q.vec[q.rear] = bt;
q.layer[q.rear] = 1;
q.locate[q.rear] = 20;
q.rear = q.rear + 1;
while(q.front < q.rear)
{
bt = q.vec[q.front];
i = q.layer[q.front];
nLocate = q.locate[q.front];
if(j < i) //进层打印时换行
{
printf("\n");
printf("\n");
j = j + 1;
k = 0;
while(k < nLocate)
{
printf(" ");
k++;
}
}
while(k < (nLocate-1))
{
printf(" ");
k++;
}
printf("%c",bt->data);
q.front = q.front + 1;
if(bt->lchild != NULL) //左孩子不为空,入队
{
q.vec[q.rear] = bt->lchild;
q.layer[q.rear] = i + 1;
q.locate[q.rear] = nLocate - pow(2, NLAYER-i-1);
q.rear = q.rear +1;
}
if(bt->rchild != NULL) //右孩子不为空,入队
{
q.vec[q.rear] = bt->rchild;
q.layer[q.rear] = i + 1;
q.locate[q.rear] = nLocate + pow(2, NLAYER-i-1);
q.rear = q.rear +1;
}
}
}