⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prg10_2.cpp

📁 这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言描述-应用模板库STL>陈君 译 英文名称是Data Structures with C++ Using STL.
💻 CPP
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -