q=p->parent->parent; /*然后把它们从链表中删掉*/
t=(struct tree*)malloc(sizeof(struct tree));
t->lchild=p; /*频度:左儿子<=右儿子*/
t->rchild=p->parent;
t->m=p->m+p->parent->m;
t->rchild->parent=t;
t->rchild->sign=1;
t->lchild->parent=t;
t->lchild->sign=0;
t->sign=-1;
root=t; /*root为根结点*/
root->parent=NULL;
if(q!=NULL){ /*判断链表是否为空*/
head=q;
r=head;
e=head; /*把新生成的根结点插入到链表中去*/
if(head->m>t->m){ /*判断是否为头节点*/
t->parent=q;
head=t;
}
else{
r=r->parent;
while(r!=NULL&&r->m m){
e=r;
r=r->parent;
}
t->parent=r;
e->parent=t;
}
p=head;
root=t;
}
else break; /*如果链表为空则结束*/
}
}
/******************************编码******************************/
void ccode(){
struct tree *p,*q;
int j;
printf(" codes as follows: characters code ");
for(j=0;j<size;j++){ p="" <="">
head=NULL;
p=ps[j]; /*从叶到根求编码*/
printf("%c ",p->data);
while(p->parent!=NULL){ /*把编码存入栈中*/
q=(struct stack *)malloc(sizeof(struct stack));
q->data=p->sign;
q->next=head;
head=q;
p=p->parent;
}
q=head; /*输出编码*/
while(q!=NULL){
printf("%d",q->data);
q=q->next;
}
printf(" ");
}
}
/******************************译码******************************/
char translate(){
struct tree *r,*p,*q;
int n;
char c;
/*读取01序列*/
Error: printf(" Input codes consist of 0 and 1 (end of ENTER): ");
n=get);
if(n!= ){ /*读取第一个字符*/
p=(struct tree*)malloc(sizeof(struct tree));
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-35162-3.html
总在说数量
不行了不行了我受不了新表情的诱惑了还有四天我就升级
敢独立就可以挂上五星红旗