您的位置:首页 > 编程语言 > Go语言

Huffman Algorithm (ii) 计算字符权重

2014-10-22 20:09 99 查看
/*
*==========================================================
* Filename    :  cw.cpp
* Description :
*
* Author      :  RollStone (rs), jealdean@outlook.com
* Created     :  10/11/2014 11:02
* Version     :  1.0
* Last_Change :  2014-10-11 11:37:33
* Copyright   :  All Rights Reserved. Copyright(c) 2007-2014
*==========================================================
*/
#include <stdio.h>
struct cwu
{
char c;
int  w;
cwu()
{
c=0,w=0;
}
};
cwu* count_weight(char *s)
{
cwu *newCWU=new cwu[256];
if(!newCWU)
{
return NULL;
}
char ci;
cwu *p;
while((ci=*s++)!=0)
{
if(ci==','||ci=='.')
{
continue;
}
p=newCWU;
do
{
if(p->c==0)
{
p->c=ci;
p->w++;
break;
}
if(p->c==ci)
{
p->w++;
break;
}
p++;
}while(1);
}
return newCWU;
}
void output_info(cwu* pc)
{
while(pc->c!=0)
{
printf("(%c,%d) ",pc->c, pc->w);
pc++;
}
printf("\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: