-->
当前位置:首页 > 题库

PROGRAMMING:Constructing Huffman tree unordered input

Luz5年前 (2021-05-10)题库520
Construct a Huffman tree and output its middle order sequence.
Given the word frequency (no more than 10, the input value is not orderly input), the Huffman tree is constructed according to the word frequency.
In order to ensure the uniqueness of the constructed Huffman tree, this paper makes the following restrictions:
(1) When selecting the two binary trees with the minimum weight of the root node, the one with the smaller weight is selected as the left subtree.
(2) If the weights of root nodes of multiple binary trees are equal, they are divided into left and right according to the order. The first one is the left subtree, and the second one is the right subtree.
###Input format:
Input the number of word frequency in the first line; On the second line, enter each word frequency in descending order
###Output format:
Output middle sequence, separated by a space
###Input example:
```in
three
1 2 1
```
###Output example:
```out
2 4 1 2 1
```







answer:If there is no answer, please comment