問題如下: 1. The purpose here is to replace the original weighting rule of the union operation, which is based on the size (number of nodes) of the tree, with a different rule based on the height of the tree. Simply said, when doing union, the root of the tree with the smaller height is made a child of the root of the tree with the larger height. 2. Note: To make results consistent, when the two trees have the same height, use the root with the smaller index as the root of the combined tree. 3. Use the same array representation as in the textbook. However, parent[i], when i is a root node, should contain a negative number whose absolute value is the height of the tree. 4. This task will be arranged similar to the equivalence class problem. The first number in the input file (inputDS.txt) is the number of items. The items are indexed starting from 0. In the second line, each pair of integers indicate an equivalent pair; pairs are separated by semicolons. An example input file looks like this: 12 0 4; 3 1; 6 10; 8 9; 7 4; 6 8; 3 5; 2 11; 11 0 5. Read in the file in the main function and follow the steps in the slides, using height-based union. No need to do collapsing find though. 6. At the end, print to the screen the contents of the array parent. For the example input above, the output should look like -3 -2 0 1 0 1 -3 0 6 8 6 2
我自己設計的程式
執行出來的結果沒有辦法和上面的example相符......
找不出原因
希望可以提供"完整的程式碼"
讓我可以對照檢視
This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
You are receiving this email because you subscribed to this feed at blogtrottr.com.
留言列表