各位各位大哥大姐大叔大婶你好大哥再见微盘呀,紧急求救...

说三道四技术文摘-感悟人生的经典句子
> 文档快照
编辑:说三道四文库
发布时间: 07:19
149页习题5.2或者152页习题5.6,如各位有现成程序请提供,如实在无给写提示或部分代码也行,十万火急,问题解决后必重谢~
联系信箱:
请帮忙发到,上面邮箱不好用了我没有书啊!我也是,能不能给出题目来?题目呢?问题描述:利用哈夫曼编码进行通信可以大大提高信道利用率,缩短信息传输时间,降低传输成本。但是,这要求再发送端通过一个编码系统对待数据预先编码,在接受端将传来的数据进行译码。对于双工信道,每端都需要一个完整的编/译码系统。试为这样的信息收发战写一个哈夫曼码的编/译码系统。
基本要求:
一个完整的系统应具有一下功能:
(1)I:初始化(Initialization)。从终端读入字符集大小n,以及n个字符和n个权值,建立哈夫曼树,并将它存于文件hfmtree中。
(2)E:编码(Encoding)。利用以建好的哈夫曼树(如不存在内存,则从hfmtree中读入),对文件tobetran中的正文进行编码,然后将结果存入文件codefile中。
(3)D:译码(Decoding)。利用已建好的哈夫曼树将文件codefile中的代码进行译码,结构存入文件textfilezhong。
(4)P:印代码文件(Print)。将文件codefile以紧凑格式显示在终端上,每行50个代码。同时将此字符形式的编码文件写入文件codeprin中。
(5)T:印哈夫曼树(Tree&printing)。将已在内存中的哈夫曼树以直观的方式(树或凹入表形式)显示在终端上,同时将此形式的哈夫曼树写入文件treeprint中。
实现提示:
(1)文件codefile的基础类型可以设为子界型bit=0..1。
(2)用户界面可以设计为“菜单”方式:显示上述功能符号,再加上“Q”,表示退出运行Quit。请用户键入一个选择功能符。此功能执行完毕后再显示此菜单,直至某次用户选择了“Q”为止。
(3)再程序的一次执行过程中,第一次执行I,D或C命令之后,哈夫曼树已经再内存了,不必再读入了。每次执行中不一定执行I命令,因为文件hfmtree可能早已建好。呵呵,我有发我一份阿,老大&给我一份,什么时候是deadline?我给你个我自己写的哈夫曼:
跟你的要求大致是一样的,你参考一下题目要求:1)建立一正文文件(本程序中建立的文件名文test.txt),向其中输入字符(本程序中可输入任意ASCII值)
&&&&&&&&&&2)通过哈夫曼算法求出文件中字符的相应编码
&&&&&&&&&&3)建立一与正文文件(test.txt)对应的编码文件(本程序中为bainma.txt)
//////////////////////////////////////////////////////////////////////////////////
#include&stdio.h&
#include&alloc.h&
#include&conio.h&
#include&stdlib.h&
#include&string.h&
/*声明两种链表结构----start*/
struct&node_a{&&/*链表1-----作用:用来统计文件中字符的个数和种类(通过count)*/
&&struct&node_a&*
typedef&struct&node_a&node,*
list&head=NULL;
struct&nodeb{&&/*链表2-----作用:用来建立用相应的编码代替字符的新文件*/
&&struct&nodeb&*
typedef&struct&nodeb&node_b,*list_b;&&/*jiang&bianma&xieru&wenjian*/
list_b&head_b=NULL;
/*声明两种链表结构----end*/
/*哈夫曼算法种相关的3种结构的声明-----start*/
struct&forest{&&
struct&alphabet{
&&char&*&&&&&&
struct&tree{
typedef&struct&tree&*tree_ptr,tree_
typedef&struct&forest&*forest_ptr,forest_
typedef&struct&alphabet&*alphabet_ptr,alphabet_
tree_ptr&tree1;
forest_ptr&forest1;
alphabet_ptr&alphabet1;
int&lasttree,
int&least,
/*哈夫曼算法种相关的3种结构的声明-----end*/
/**************stack&difination&start****************/
struct&stacknode{
&&char&*bian_
&&struct&stacknode&*
typedef&struct&stacknode&stack_
typedef&stack_node&*
link&top=NULL;
void&push(char&*item){
&&if(top!=NULL){
&&&&p=(link)malloc(sizeof(stack_node));
&&&&if(p==NULL){
&&&&printf("Memory&allocation&error!");
&&&&p-&bian_ma=
&&&&p-&next=
&&&&top=p;
&&&&top=(link)malloc(sizeof(stack_node));
&&&&if(!top){
&&&&&&printf("Memory&allocation&error!");
&&&&top-&bian_ma=
&&&&top-&next=NULL;
void&pop(void){
&&top=top-&
&&free(p);
void&makenull(void){
&&while(top!=NULL)
&&&&pop();
int&empty(){
&&if(top==NULL)
&&return&1;
&&return&0;
char*&tops(void){
&&&&return&(top-&bian_ma);
void&display_stack(link&s){&/*显示栈重的内容*/
&&while(ptr!=NULL){
&&printf("%s",ptr-&bian_ma);
&&ptr=ptr-&
&&/***************************stack__difination&is&end************************/
void&display(list&h){&/*显示链表1*/
while(ptr!=NULL){
&&printf("%d,%c,%d\n",i,ptr-&data,ptr-&count);
&&ptr=ptr-&
void&display_b(list_b&h){&&/*显示链表2*/
while(ptr!=NULL){
&&printf("%d,%c\n",i,ptr-&data);
&&ptr=ptr-&
void&insert(char&item){&&/*用于插入元素以建立链表1*/
&&list&temp,
&&ptr=head-&
&&if(ptr==NULL){
head-&next=(list)malloc(sizeof(node));
&&&&head-&next-&data=
&&&&head-&next-&count=1;
&&&&head-&next-&next=NULL;
&&&&while(ptr!=NULL){
&&&&&&if(ptr-&data==item){
&&&&&&ptr-&count=ptr-&count+1;
&&&&&&flag=1;
&&&&ptr=ptr-&
&&&&if(flag==1)
&&&&&&temp=ptr-&
&&&&&&ptr-&next=(list)malloc(sizeof(node));
&&&&&&ptr-&next-&data=
&&&&&&ptr-&next-&count=1;
&&&&&&ptr-&next-&next=
void&insert_b(char&item){&&/*插入元素以建立链表2*/
&&list_b&ptr_b,temp_b;
&&ptr_b=head_b;
&&if(ptr_b-&next==NULL){
&&&&head_b-&next=(list_b)malloc(sizeof(node_b));
&&&&head_b-&next-&data=
&&&&head_b-&next-&next=NULL;
&&&&while(ptr_b-&next!=NULL){
&&ptr_b=ptr_b-&
&&&&ptr_b-&next=(list_b)malloc(sizeof(node_b));
&&&&ptr_b-&next-&data=
&&&&ptr_b-&next-&next=NULL;
void&search(void){&/*搜索文件并将文件中的数据分别存入作用不同的链表中*/
&&if((fp=fopen("test.txt","r"))==NULL)
&&&&printf("Reading&error!\n");
&&while(!feof(fp)){
&&&&ch=getc(fp);
&&&&if(ferror(fp)){
&&&&&&printf("error!\n");
&&&&if(ch==EOF)
&&&&insert(ch);&&/*插入元素进链表1*/
&&&&insert_b(ch);&/*插入元素进链表2*/
&&printf("\n");
&&fclose(fp);
void&display_struct(int&n){&/*显示哈夫曼算法中的3个结构树组&*/
printf("\n\n=======================================\n\n");
printf("FOREST_STRUCT_ARRY&:\n\n\n");
for(i=0;i&=n;i++){
printf("%f,%d\n",forest1[i].weight,forest1[i].root);
printf("\n\nALPHABET_STRUCT_ARRY&:\n\n\n");
for(i=0;i&=n;i++){
&&printf("%f,%d,%c\n",alphabet1[i].probability,alphabet1[i].leaf,alphabet1[i].symbol);
printf("\n\nTREE_STRUCT_ARRY&:\n\n\n");
for(i=0;i&=2*n-1;i++)
printf("%d,%d,%d\n",tree1[i].lchild,tree1[i].rchild,tree1[i].parent);
printf("\n\n======================================\n\n");
int&init_struct(void){&&/*初始化哈夫曼算法中3种结构数组*/
float&count=.0;
int&i=1,n=0;
ptr=head-&
while(ptr!=NULL){
&&count=ptr-&count+
&&ptr=ptr-&
ptr=head-&
forest1=(forest_ptr)malloc(sizeof(forest_node)*n+sizeof(forest_node));
alphabet1=(alphabet_ptr)malloc(sizeof(alphabet_node)*n+sizeof(alphabet_node));
tree1=(tree_ptr)malloc(sizeof(tree_node)*n*2-sizeof(tree_node));
forest1[0].weight=alphabet1[0].probability=0.0;
forest1[0].root=alphabet1[0].leaf=0;
alphabet1[0].symbol='0';
while(ptr!=NULL){
&&forest1[i].weight=alphabet1[i].probability=ptr-&count/
&&forest1[i].root=alphabet1[i].leaf=i;
&&alphabet1[i].symbol=ptr-&
&&ptr=ptr-&
for(i=0;i&=2*n-1;i++){
&&tree1[i].lchild=0;
&&tree1[i].rchild=0;
&&tree1[i].parent=0;
void&creat(void){&&&&&&/*创建正文文件test.txt*/
&&FILE&*fp,*
&&if((fp=fopen("test.txt","w+t"))==NULL)
&&&&printf("Creat&error!\n");
&&printf("Input&the&data:\n");
&&ch=getch();
&&putch(ch);
&&while(ch!='#'){
&&&&putc(ch,fp);
&&&&ch=getch();
&&&&putch(ch);
&&&&fclose(fp);
void&creat_bianma(int&number){&&/*根据哈夫曼算法建立文件中各种字符对应的编码*/
&&int&i,j,n;
&&char&*bm=malloc(sizeof(char)*number);
&&for(n=1;n&=n++){
&&&&j=i=n;
&&&&makenull();
&&&&p=tree1[i].
&&&&while(tree1[p].parent!=0){
if(tree1[p].lchild==i)
&&&&&&push("0");
&&&&&&push("1");
p=tree1[p].
&&&&if(tree1[p].lchild==i)
&&push("0");
&&push("1");
&&&&strcpy(bm,"&");&/*目的:使创建编码文件中的各编码中间存在间隔*/
&&&&while(!empty()){
strcat(bm,tops());
&&&&&&alphabet1[j].bianma=malloc(sizeof(char)*number);
&&&&&&strcpy(alphabet1[j].bianma,bm);
&&&&&&printf("\n%c:%s",alphabet1[j].symbol,alphabet1[j].bianma);&/*打印出相应的编码*/
&&&&&&getch();
void&write_new_file(int&number){&/*根据相应的编码重新建立编码文件*/
&&char&*ch=malloc(sizeof(char)*number);
&&ptr=head_b-&
&&if((fp=fopen("bianma.txt","w"))==NULL)
&&&&printf("Write&in&a&new&file&error!");
&&&&while(ptr!=NULL){
&&&&&&for(i=1;i&=i++){
if(ptr-&data==alphabet1[i].symbol){
&&&&strcpy(ch,alphabet1[i].bianma);
&&&&fputs(ch,fp);
&&&&&&ptr=ptr-&
&&fclose(fp);
void&main(void){
void&huffman(void);
void&lightones();
head=(list)malloc(sizeof(node));
head-&next=NULL;
head-&data='';
head-&count=0;
head_b=(list_b)malloc(sizeof(node_b));
head_b-&data='';
head_b-&next=NULL;
&&system("cls");
&&creat();
&&search();
&&printf("\nlianbiao1:\n");
&&display(head);/*显示链表1*/
&&getch();
&&printf("\nlianbiao2:\n");
&&display_b(head_b);
&&getch();
&&num=init_struct();
&&printf("\n");
&&printf("The&3&init_struct&of&huffman?\n");
&&display_struct(num);/*显示初始化的哈夫曼书的相关3个结构数组*/
&&lastnode=
&&lasttree=
&&huffman();
&&printf("Now&the&3&struct&through&huffman&shuanfa\n");
&&display_struct(num);/*显示哈夫曼树中相关的3种结构(经过哈夫曼算法处理)*/
&&printf("\nThe&bian_ma&is:\n");
&&creat_bianma(num);
&&write_new_file(num);
&&printf("\nDo&you&want&to&re_try(y/n)?");
&&ch=getchar();
&&}while(ch=='y');
/*哈夫曼算法-----defination_start*/
void&lightones(void){
&&if(forest1[1].weight&=forest1[2].weight){
&&&&least=1;
&&&&second=2;
&&&&least=2;
&&&&second=1;
&&for(i=3;i&=i++)
&&&&if(forest1[i].weight&forest1[least].weight){
if(forest1[i].weight&forest1[second].weight)
&&second=i;
int&creat_tree(int&lefttree,int&righttree){
&&lastnode=lastnode+1;
&&tree1[lastnode].lchild=forest1[lefttree].
&&tree1[lastnode].rchild=forest1[righttree].
&&tree1[lastnode].parent=0;
&&tree1[forest1[lefttree].root].parent=
&&tree1[forest1[righttree].root].parent=
&&return(lastnode);
void&huffman(void){
&&int&i,j;
&&while(lasttree&1){
&&&&lightones();
&&&&newroot=creat_tree(i,j);
&&&&forest1[i].weight=forest1[i].weight+forest1[j].
&&&&forest1[i].root=
&&&&forest1[j]=forest1[lasttree];
&&&&lasttree=lasttree-1;
/*哈夫曼算法-----defination&end*/
编译环境:windows_2000P&&TURBOC_2.0
我的上网环境必须变了。要不然这么长的源代码从那来?看看给分给分!!
让你一劳永逸:
http://dsite./xtjd.htm
自己看去。
给分给分!!
备案号: 说三道四&&南京哪里组装电脑便宜点,学生不容易呢,2000块能配什么样的电脑(主 ...
南京哪里组装电脑便宜点,学生不容易呢,2000块能配什么样的电脑(主机+显示器),拜托各位大哥大姐了!!!
大婶们,帮我弄下配置清单吧,拜托了!!!!! ***配齐了2200块是底线了啊,暑期家教赚的零花钱哎, 一:显示器液晶的吧,
二:内存2个G的,
三:操作系统XP的, 四:机箱外壳差点没事!
五:只要能玩 起凡三国
跑跑卡丁车 和冒险岛就可以了!!!!
这些游戏对配置要求很低的!!! 六:
兼容要好点的,不要老出问题的!!!! 七:
光驱弄个差点的吧,主要考虑平时自己装系统方便点,
来找我吧呵呵我也是暑假打工的!给你留个Q
提问者的感言:谢谢您的解答!
其他回答3条
在京东上买吧 CPU 英特尔(intel) 45纳米 奔腾双核处理器 E5400盒装CPU(LGA775/2.7GHz/2M二级缓存/800MHz)
¥449 主板 华硕(ASUS)P5KPL-AM SE(INTEL G31 /LGA 775) ¥399
内存 金士顿(Kingston)DDR2 800 2G 台式机内存
硬盘 希捷(Seagate)500G ST3500418AS 7200转16M SATAII金装硬盘联强货 正品行货三年免费全国联保
¥299 显示器 宏碁(eMachines)E203HVb 20英寸宽屏液晶显示器 ¥759 键鼠 微软(Microsoft)键鼠套装 光学精巧套装500 黑色
¥89 机箱 上普(Super)电脑机箱 优酷-MV873(含350WB静音版电源) ¥179 共计
2393 钱不够可以在显示器上下下功夫。 装机很容易的~~~
本回答正在审核中...
去电脑城就是 配置用 3A的配置 下面那个 英特尔配置不带独立显卡的 3A的配出来可以带独立显卡 鼠标键盘 叫老板送 光驱不买 买个U盘 用U盘装系统一样的 才20快钱 节约100 其他的 差不多 就把那CPU换成AMD 板子换快AMD平台的就行了 像GIGA M61 之类的主板 加通路货显卡
加 AMD240 这类的CPU 绝对是平民的选择 英特尔死活就比AMD贵些 谁叫人家牛B
问答为您推荐
市场价:暂无
网友正在问
||||||||||
Copyright (C) 1999-, All Rights Reserved 版权所有 天极网络

参考资料

 

随机推荐