标签:二叉树
1、二叉树定义
typedef struct BTreeNodeElement_t_ { void *data; } BTreeNodeElement_t; typedef struct BTreeNode_t_ { BTreeNodeElement_t *m_pElemt; struct BTreeNode_t_ *m_pLeft; struct BTreeNode_t_ *m_pRight; } BTreeNode_t;
对任意一个给定子树的节点数,左子树节点数+右子树节点数+1,加1是加上根节点自身
(1)递归方式:
如果给定根节点为NULL,则返回0;
如果给定根节点不为NULL,则返回: 左子树节点数+右子树节点数+1
int GetBTreeNodesTotal( BTreeNode_t *pRoot){ if( pRoot == NULL ) return 0; return ( GetBTreeNodesTotal( pRoot->m_pLeft) + GetBTreeNodesTotal( pRoot->m_pRight) + 1); }
(2)非递归方式:
任意一种遍历方式: 前序、后序、中序、按层遍历方式都可以
标签:二叉树
原文地址:http://blog.csdn.net/beitiandijun/article/details/41931377