标题:如何理解哈夫曼树
只看楼主
努力,幸运
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-5-9
结帖率:0
已结贴  问题点数:20 回复次数:3 
如何理解哈夫曼树
/*构造哈夫曼树的n-1个非叶节点*/
    for (i = 0; i < n - 1; i++)
    {
        m1 = m2 = MaxValue;
        x1 = x2 = 0;
        for (j = 0; j < n - 1; j++)
        {
            if (haffTree[j].weight < m1&&haffTree[j].flag == 0)         
            {
                m2 = m1;                                                    //此处赋值
                x2 = x1;
                m1 = haffTree[j].weight;
                x1 = j;
            }
            else if (haffTree[j].weight < m2&&haffTree[j].flag == 0)            //那么此处不就是和上面的判断一样吗这里的m2等于上面的m1,最后怎么的出两个最小的权值呢?
            {
                m2 = haffTree[j].weight;
                x2 = j;
            }
        }
搜索更多相关主题的帖子: 如何 
2016-05-09 18:20
努力,幸运
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-5-9
得分:0 
顶一下
2016-05-09 18:36
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
得分:20 
用debug跟踪一下这个程序

程序代码:
#include <stdio.h>

int main()
{
    int sa[] = { 5, 7, 1, 3, 6, 2, 4, 2, 9, 7};
    int size = sizeof(sa) / sizeof(sa[0]);
    int x1, x2, m1, m2;

    m1 = m2 = 100;
    x1 = x2 = 0;
    for (int i = 0;i < size;i++)
    {
        if (sa[i] < m1)
        {
            m2 = m1;
            x2 = x1;

            m1 = sa[i];
            x1 = i;
        }
        else if (sa[i] < m2)
        {
            m2 = sa[i];
            x2 = i;
        }
    }

    printf("x1 = %d, m1 = %d\n", x1, m1);
    printf("x2 = %d, m2 = %d\n", x2, m2);
}



[fly]存在即是合理[/fly]
2016-05-10 11:02
cdm157183
Rank: 2
等 级:论坛游民
帖 子:4
专家分:10
注 册:2016-3-25
得分:0 
以下是引用努力,幸运在2016-5-9 18:20:02的发言:

/*构造哈夫曼树的n-1个非叶节点*/
    for (i = 0; i < n - 1; i++)
    {
        m1 = m2 = MaxValue;
        x1 = x2 = 0;
        for (j = 0; j < n - 1; j++)
        {
            if (haffTree[j].weight < m1&&haffTree[j].flag == 0)         
            {
                m2 = m1;                                                    //此处赋值
                x2 = x1;
                m1 = haffTree[j].weight;
                x1 = j;
            }
            else if (haffTree[j].weight < m2&&haffTree[j].flag == 0)            //那么此处不就是和上面的判断一样吗这里的m2等于上面的m1,最后怎么的出两个最小的权值呢?
            {
                m2 = haffTree[j].weight;
                x2 = j;
            }
        }


Live the life you love and love the life you live.
2016-05-17 16:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464572-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.552378 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved