通行证│用户名: 密码: 验证码: 验证码,看不清楚?请点击刷新验证码 电信网通铁通移动   在线
资源搜索:
热门搜索:Linux VB C语言 PhotoShop Flash TCP/IP
   首页 | 文章 | 软件 | 动画 | 资源 | 励志 | 骗术 | 论坛 | 邮箱 | 会员中心 | 军事 | 科技 | 博客 | 图片 | 商城 | 最新更新 | 800g资源 | 爱心黑客
您现在的位置: 爱国者黑客 >> 资源 >> 程序设计 >> C#语言 >> 基础教程 >> 文章正文

上一页  [1] [2] 

霍夫曼树编码的实现
责任编辑:admin   更新日期:2005-8-6
bsp; (*s2)=(*s1);
                        (*s1)=temp3;
                    }
                }
                else
                {
                    if(HT[i].Weight<temp1)
                    {
                        temp2=temp1;
                        temp1=HT[i].Weight;

                        (*s2)=(*s1);
                        (*s1)=i;
                    }
                    if(HT[i].Weight>temp1&&HT[i].Weight<temp2)
                    {
                        temp2=HT[i].Weight;
                        (*s2)=i;
                    }
                }
            }
        }
    }
}

int LookFor(char *str,char letter,int count)
{
    int i;
    for(i=0;i<count;i++)
    {
        if(str[i]==letter) return i;
    }
    return -1;
}
void OutputWeight(char *Data,int Length,
                  char **WhatLetter,
                  int **Weight,int *Count)
{
    int i;
    char* Letter=(char*)malloc(Length);
    int* LetterCount=(int *)malloc(Length);
    int AllCount=0;
    int Index;
    int Sum=0;
    float Persent=0;

    for(i=0;i<Length;i++)
    {
        if(i==0)
        {
            Letter[0]=Data[i];
            LetterCount[0]=1;
            AllCount++;
        }
        else
        {
            Index=LookFor(Letter,Data[i],AllCount);
            if(Index==-1)
            {
                Letter[AllCount]=Data[i];
                LetterCount[AllCount]=1;
                AllCount++;
            }
            else
            {
                LetterCount[Index]++;
            }
        }
    }
    for(i=0;i<AllCount;i++)
    {
        Sum=Sum+LetterCount[i];
    }
    (*Weight)=(int*)malloc(AllCount);
    (*WhatLetter)=(char*)malloc(AllCount);

    for(i=0;i<AllCount;i++)
    {
        Persent=(float)LetterCount[i]/(float)Sum;
        (*Weight)[i]=(int)(1000*Persent);
        (*WhatLetter)[i]=Letter[i];
    }
    (*Count)=AllCount;
}

 
  • 上一篇文章:
  • 下一篇文章:
  • 热门文章
    Olldbg常见问题
    汇编语言的艺术(组合语言的艺术)--观
    汇编语言的艺术(组合语言的艺术)--准
    汇编语言的艺术(组合语言的艺术)--基
    汇编语言的艺术(组合语言的艺术)--基
    汇编语言---程式设计 (4)
    虚拟8086模式
    SYS命令使用说明
    javascript + CSS 实现动态菜单显
    推荐文章
    自制Windows XP SP2自动安装光盘
    SQLServer注入工具改进版 v1.02
    使用photoshop CS进行自然美肤
    Photoshop绘制诺基亚手机
    PHOTOSHOP制作秋日之梦
    PHOTOSHOP鼠绘名模王爱萍
    Photoshop制作晶莹飞溅的水珠
    教你用PHOTOSHOP做放大镜
    鼠绘美女及服装修画全过程