#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <malloc.h>
#define maxlen 30
typedef struct Node
{
struct Node * leftChild;
struct Node * rightChild;
int key;
}Node;
Node *initTree()
{
int n = 0;
scanf("%d",&n);
if(0 == n){
return NULL;
}
Node *p = (Node *)malloc(sizeof(Node));
p->key = n;
p->leftChild = initTree();
p->rightChild = initTree();
return p;
}
void preOrderRecursive(Node *root)
{
if(root){
printf("%d\n",root->key);
preOrderRecursive(root->leftChild);
preOrderRecursive(root->rightChild);
}
}
int getResult(Node *pTree)
{
Node *queue[maxlen];
int front = 0;
int rear = 0;
int count = 0;
queue[(++rear)%maxlen] = pTree;
int last = 1;
while(front != rear){
Node *tmp = queue[(++front)%maxlen];
if(tmp->leftChild == NULL && tm
求二叉树最浅叶子结点们的和
最新推荐文章于 2025-09-24 22:38:33 发布
这篇博客探讨了如何利用图的宽度优先遍历(BFS)算法,解决求解二叉树中最浅叶子节点之和的问题。通过对二叉树进行层次遍历,可以有效地找到距离根节点最近的叶子节点,并累加它们的值。

最低0.47元/天 解锁文章
2281

被折叠的 条评论
为什么被折叠?



