prg10_2.cpp
来自「这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言」· C++ 代码 · 共 43 行
CPP
43 行
// File: prg10_2.cpp
// the program builds the sample Tree 1 and calls
// countLeaf() to determine the number of leaf nodes
// in the tree. it then calls depth() to compute
// the depth of the tree
#include <iostream>
#include "d_tnode.h" // tnode class
#include "d_tnodel.h" // tnode library
using namespace std;
int main()
{
// root of the tree
tnode<char> *root;
int leafCount;
// use the character Tree 1
root = buildTree(1);
// we accumulate the number of leaf nodes in leafCount,
// so it must have initial value 0
leafCount = 0;
// call countLeaf() and output leaf count
countLeaf(root, leafCount);
cout << "Number of leaf nodes is " << leafCount << endl;
// make call to depth() and output the depth of the tree
cout << "The depth of the tree is "
<< depth(root) << endl;
return 0;
}
/*
Run:
Number of leaf nodes is 4
The depth of the tree is 3
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?