标签:io ar os sp on ef amp as new
#include <iostream> using namespace std; typedef struct tagNode { char data; tagNode *lchild; tagNode *rchild; }*PNode; void createtree(PNode &T) { char c; cin >> c; if(c == ',')return; else { T = new tagNode; T->data = c; T->lchild = NULL; T->rchild = NULL; createtree(T->lchild); createtree(T->rchild); } } int helper(const PNode T, const PNode root) { if( T == NULL)return 0; int ldepth = helper(T->lchild,root); int rdepth = helper(T->rchild,root); if( T == root) return ldepth+rdepth+1; else return max(ldepth,rdepth)+1; } int TreeMaxDistance(PNode T) { helper(T,T); } int main() { PNode T = NULL; createtree(T); if( T == NULL)return 0; cout << TreeMaxDistance(T) << endl;; }
标签:io ar os sp on ef amp as new
原文地址:http://blog.csdn.net/jiangge123456/article/details/41825671