Algorithm serial (3) - generates the most exceeding and tree

xiaoxiao2021-03-05  21

1. Problem Description: Take N the classified files to return to the classified files pair and in a file. For example, if X1, X2, X3, X4 are files to be merge, then X1, X2 can be normalized to Y1, and then Y1 and X3 are merged into Y2, and final Y2 and X4 are returned and to obtain a desired classification file. Using the optimal two-way merge method, the result of the summary has a binary tree that wants to correspond to the outer path of the outer path, so the problem is converted into the forest, and it is a forest, merged into a forest. Two dollars.

2. Design Thought and Analysis: Basic Thoughts: (1) Assuming a given set of weight {W1, W2, ..., Wn}, thus can generate forest f = {T1 made from N binary tree , T2, ..., TN}, where each tree has a root node that is Wi; (2) Select the smallest weight of two tree root nodes in the forest F, as a tree The left and right bonus of the new tree and the weight of the root nodes of the new tree are the sum of the weights of the root nodes of the left and right subtots; (3) Deleting the two of the forest f Tree, while adding new trees to the collection f; (4) Repeating 2, 3 steps to the new forest, until there is only one binary tree left, this is the tree you want.

#include "iostream.h"

Struct huffmannode {int uste; int lchild, rchild;}; structure of node ///

Class Huffmantree {public: huffmannode * node;

PUBLIC: Tree (int weightnum);

Huaffmantree Class

HUFFMANTREE :: Tree (int Weightnum) {INT I, J, POS1, POS2; INT min1, min2; node = new struct huffmannode [2 * weightnum-1]; for (i = 0; i > Node [i] .weight; node [i] .parent = -1; node [i] .lchild = -1; Node [i] .rchild = -1;} / * join and creat Tree * /// for (i = weightnum; i <2 * weightnum-1; i ) {POS1 = -1; POS2 = -1 Min1 = min2 = 32762; j = 0; while (j <= i-1) {IF (Node [J] .parent == - 1) {if (Node [J] .weight <= min1) {min2 = Min1; min1 = node [j] .weight; pOS2 = POS1; POS1 = J;} else if (node ​​[j] .weight

} // creat a btree ////

转载请注明原文地址:https://www.9cbs.com/read-36278.html

New Post(0)