huffman编码
要求:建立一个文本文件,统计该文件中各字符频率,对各字符进行huffman编码,将该文件翻译成huffman编码文件,再将huffman编码文件翻译成原文件。 有哪位高手可以帮帮忙? :答案要能无错误地运行。期限为两天。如果没有更好的答案就采用第一个了。(文本的字符是abcdeabcdeabceabceacecc ) #include<stdio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
const MAXSIZE=100;
typedef struct Huffmantree
{
char cname;
int weight,mark;
struct Huffmantree *parent,*lchild,*rchild,*next;
}Hftree,*linktree;
linktree tidy_string(char ch[])
{
int i=0;
linktree tree,ptr,beforeptr,node;
tree=(linktree)malloc(sizeof(Hftree));
if(!tree)
return NULL;
tree->next=NULL;
for(i=0;ch[i]!='\0'&&ch[i]!='\n';i++)
{
ptr=tree;
beforeptr=tree;
node=(linktree)malloc(sizeof(Hftree));
if(!node)
return NULL;
node->parent=NULL;
node->lchild=NULL;
node->rchild=NULL;
node->next=NULL;
node->mark=0;
node->cname=ch[i];
node->weight=1;
if(tree->next==NULL)
tree->next=node;
else
{
ptr=tree->next;
while(ptr&&ptr->cname!=node->cname)
{
ptr=ptr->next;
beforeptr=beforeptr->next;
}
if(ptr&&ptr->cname==node->cname)
{
ptr->weight+=1;
free(node);
参与评论- 相关内容
- 最近更新
- ·NKA6288冲电一般冲多少时间为好?
- ·什么叫双卡双待机
- ·关于三星手机SGH-D808连接电脑的..
- ·国产手机最差的是哪个品牌
- ·松下EB-BHX70蓝牙耳机的通行码是..
- ·qq密码!!急!!
- ·现在的qq自定义头像能不能用Q币买..
- ·qq网络电视看不了!!!
- ·杂建QQ群
- ·普通用户在QQ商城买的QQ空间商品..
添加到百度搜藏