码迷,mamicode.com
首页 > 其他好文 > 详细

Huffman Algorithm (ii) 计算字符权重

时间:2014-10-11 23:20:46      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:des   blog   io   ar   sp   div   2014   on   log   

/*
 *==========================================================
 * 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");
}

 

Huffman Algorithm (ii) 计算字符权重

标签:des   blog   io   ar   sp   div   2014   on   log   

原文地址:http://www.cnblogs.com/jealdean/p/4019863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!