图&树
rose2333
这个作者很懒,什么都没留下…
展开
-
编程之美。求二叉树节点最大距离
求出每个节点的高度(即该节点到子树最远叶节点的距离),最大距离的路径一定会经过某个子树的树根 在深度遍历时维持一个dis作为最大距离; #include using namespace std; int dis = 0; struct node { int longs;//最长节点 node* l; node* r; }; void find(node* r原创 2016-09-11 21:50:58 · 214 阅读 · 5 评论 -
编程之美。分层遍历二叉树(使用队列)
层次遍历二叉树用队列是非常适合的,若需要打印出第n层的节点数据,只需要在队列中加入一个标记来分层(我使用的是NULL) #include #include using namespace std; struct Node { int t; Node *left, *right; Node(int t, Node * l = NULL, Node * r = NUL原创 2016-09-11 23:21:34 · 252 阅读 · 0 评论