C++霍夫曼编码(Huffman Coding)的代码

如下代码内容是关于C++霍夫曼编码(Huffman Coding)的代码。

 

#include<iostream>
#include<string>
#include<queue>
using namespace std;

class node{
public:
content=con;
weight=wht;
leftchild=left;
rightchild=right;
code=co;
}
string content;
float weight;
string code;
};

for(int i=low+1;i<high;i++){
int j=i-1;
while(array[j]->weight>tem->weight&&j>=low){
array[j+1]=array[j];
j--;
}
array[j+1]=tem;
}
}
for(int i=0;i<n;i++){
array[i]=new node(s[i],w[i],NULL,NULL,"");
}
insertion_sort(array,0,n);
int p=0;
while(p!=n-1){
array[p+1]=new_node;
p=p+1;
insertion_sort(array,p,n);
}

}

nq.push(p);
while(nq.size()!=0){
nq.pop();
if(l!=NULL){l->code=cur->code+"0"; nq.push(l);}
if(r!=NULL){r->code=cur->code+"1"; nq.push(r);}
if(l==NULL&&r==NULL){
cout<<cur->content<<": "<<cur->code<<endl;
}
}
}
string s[8]={"a","b","c","d","e","f","g","h"};
float w[8]={1,1,2,3,5,8,13,21};
create_huffman_tree(s,w,8,array);
create_huffman_code(array[7]);
}




 

posted on 2020-06-09 11:59  okhjj  阅读(408)  评论(0编辑  收藏  举报