编码问题
This commit is contained in:
+11
-8
@@ -1,26 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
*二叉树采用二叉链存储结构存放,结点值为int 类型,设计一个递归算法求二叉树 bt 中所有叶子结点值之和
|
* 二叉树采用二叉链存储结构存放,结点值为int 类型,设计一个递归算法求二叉树 bt 中所有叶子结点值之和
|
||||||
*/
|
*/
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include"BiTree.h"
|
#include"BiTree.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
BiTree *createTreeFromArray(const int *values, int size) {
|
BiTree* createTreeFromArray(const int* values, int size)
|
||||||
BiTree *root = nullptr;
|
{
|
||||||
for (int i = 0; i < size; ++i) {
|
BiTree* root = nullptr;
|
||||||
|
for (int i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
BiTree::insertNode(root, values[i]);
|
BiTree::insertNode(root, values[i]);
|
||||||
}
|
}
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
int testValues[] = {7, 3, 10, 1, 5, 9, 12};
|
int testValues[] = {7, 3, 10, 1, 5, 9, 12};
|
||||||
int size = sizeof(testValues) / sizeof(testValues[0]);
|
int size = sizeof(testValues) / sizeof(testValues[0]);
|
||||||
|
|
||||||
BiTree *root = createTreeFromArray(testValues, size);
|
BiTree* root = createTreeFromArray(testValues, size);
|
||||||
|
|
||||||
cout << "树结构为:" << endl << root->toString() << endl;
|
cout << "树结构为" << endl << root->toString() << endl;
|
||||||
cout << "叶子节点之和为: " << BiTree::sum_leaf(root) << endl;
|
cout << "叶子节点数据总和: " << BiTree::sum_leaf(root) << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user