求二叉树的所有节点数

[复制链接]
查看11 | 回复1 | 2011-11-25 11:02:06 | 显示全部楼层 |阅读模式
简单,用递归遍历时,计个数,计数变量用全局变量就可以了;int count=0;voidpreOrder(TTree:tree){
if (tree!=NULL)
{
count++;
//先根访问,且计数
if (tree->Left!=NULL)
preOrder(tree->Left);
if (tree->Right!=NULL)
preOrder(tree->Right);...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行