C++로 구현한 허프만코드 인코딩소스
본 자료는 2페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
해당 자료는 2페이지 까지만 미리보기를 제공합니다.
2페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

C++로 구현한 허프만코드 인코딩소스에 대한 보고서 자료입니다.

목차

1.결과화면

2.소스

본문내용

결과---------->>" << endl;
tree.Incoding(tree.root);
cout << endl;
return 0;
}
int Filereader(char *file_name)
{
FILE *fp;
char f;
if((fp = fopen(file_name, "r")) == NULL){
cout << "파일 열기 실패 " << file_name << endl;
return 1;
}
cout << "FILE NAME is " << file_name << endl << endl;
cout << "<<-----------파일의 내용----------->>"<< endl << "\t";
while((f=fgetc(fp)) != EOF){
cout << f;
Character(f);
}
cout << endl << endl;
Sortchar();
fclose(fp);
return 0;
}
void Sortchar()
{
Ch_element temp;
for(int i=0; i for(int j=i+1; j if(data[i].ch_count > data[j].ch_count){
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
}
void Character(char ch)
{
for(int i=0; i if(data[i].ch == ch){
data[i].ch_count++;
return;
}
data[idx].ch = ch;
data[idx].ch_count = 1;
idx++;
return;
}
void Huffman::Hfmtree(int &n, int &r, int idx){
int left, right;
int leftfg = 0, rightfg = 0;
Ch_element data;
for(int i=r; i if(node[i].data.ch_count <= node[n].data.ch_count){
if(rightfg == 0){
right = i;
r++; rightfg++;
}
else if(leftfg == 0){
left = i;
r++; leftfg++;
break;
}
}
}
if(n < num_node){
if(rightfg == 0){
right = n++;
rightfg++;
}
if(leftfg == 0){
if(n == num_node)
left = r++;
else
left = n++;
}
}
else{
right = r++;
left = r++;
}
data.ch = NULL;
data.ch_count = node[left].data.ch_count + node[right].data.ch_count;
node[idx].Insertdata(data, node[left], node[right]);
root = &node[idx];
}
void Huffman::Incoding(Node *n){
if(n->left){
ch[bit] = '0';
bit++;
ch[bit] = '\0';
Incoding(n->left);
}
if(n->right){
ch[bit] = '1';
bit++;
ch[bit] = '\0';
Incoding(n->right);
}
if(n->Leaf()){
chcode[ch_idx].ch = n->data.ch;
strcpy(chcode[ch_idx].code, ch);
cout << "문자 '"<< chcode[ch_idx].ch << "' = " << chcode[ch_idx].code << endl;
ch_idx++;
}
bit--;
ch[bit] = '\0';
}

키워드

  • 가격1,000
  • 페이지수8페이지
  • 등록일2007.05.16
  • 저작시기2007.5
  • 파일형식한글(hwp)
  • 자료번호#409899
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니