二叉树的层次遍历和二叉树的应用的简单使用
1.二叉树的层次遍历
void levelTravse(BiTree root) { if (root) { Queue q = CreateQueue(); inQueue(q, root); while (emptyQueue(q)) { BiTree e = outQueue(q); printf("%d", e->data); if (e->lchild) { inQueue(q, e->lchild); } if (e->rchild) { inQueue(q, e->rchild); } } } }
2.计算二叉树的深度
int depthBinary(BiTree root) { if (!root) { return 0; } else { return depthBinary(root->lchild) > depthBinary(root->rchild) ? depthBinary(root->lchild) + 1 : depthBinary(root->rchild) + 1; } }
好了,我们下回见,peace

浙公网安备 33010602011771号