int min1 = 9999999;//最小权值初值\n\t\tfor (j = 0; j < i; j++) {\n\t\t\tif (header[j].parent != -1)\n\t\t\t\tcontinue;\n\t\t\t/parent!=-1说明该结点已存在哈夫曼\n\t\t\t树中,跳出循环重新选择新结点/\n\t\t\tif (min1 > header[j].count) {\n\t\t\t\tpt1 = j;\n\t\t\t\tmin1 = header[j].count;\n\t\t\t}\n\t\t}\n\t\theader[i].count = header[pt1].count;\n\t\theader[pt1].parent = i;\n\t\theader[i].lch = pt1;ptl1干啥用的内容:pt1是用来记录权值最小的结点的下标,ptl1应该是笔误,正确的是pt1。在循环中,如果找到了权值最小的结点,就将其下标赋值给pt1。

哈夫曼树构建代码解析:最小权值结点选择

原文地址: https://www.cveoy.top/t/topic/pwP3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录