
树
Dunyb
坚毅
展开
-
静态二叉树
不会用指针的也能实现二叉树(静态二叉树)数组实现。struct node{ int data; int lchild; int rchild;}Node[maxn];int index = 0;int newNode(int v){ Node[index].data = v; Node[index].lchild = -1; Node[index].rchild = ...原创 2019-02-28 15:02:28 · 507 阅读 · 0 评论 -
树的遍历
树的静态写法struct node{ typename data; vector child;}Node[maxn];int index = 0;int newNode(int v){ Node[index].data = v; Node[index].child.clear(); return index++;}树的先根遍历void PreOrder(int...原创 2019-02-28 15:33:31 · 185 阅读 · 0 评论 -
1053 Path of Equal Weight (30 分)
1053Path of Equal Weight(30 分)Given a non-empty tree with rootR, and with weightWiassigned to each tree nodeTi. Theweight of a path fromRtoLis defined to be the sum of the weights o...原创 2019-02-28 16:51:27 · 185 阅读 · 0 评论 -
平衡二叉树(AVL)
初识:平衡二叉树知识点下面就是代码了。struct node { int v, height; //v 权值 height 当前子树高度 node *lchild, *rchild;};node* newNode(int v){ node* Node = new node; Node->v = v; Node->height = 1; Node->...原创 2019-02-28 20:45:27 · 302 阅读 · 0 评论 -
哈夫曼树(优先队列)合并果子
Input第一行包含一个整数T(T<=50),表示数据组数。每组数据第一行包含一个整数n(2<=n<=1000),表示果子的堆数。第二行包含n个正整数ai(ai<=100),表示每堆果子的果子数。Output每组数据仅一行,表示最小合并代价。Sample Input241 2 3 453 5 2 1 4Sample Output...原创 2019-03-01 17:15:11 · 670 阅读 · 0 评论