목차
1.결과화면
2.소스
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';
}
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
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
}
void Character(char ch)
{
for(int i=0; i
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(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';
}
추천자료
전세계의 모든 파일형식들 (파일 확장자 목록)
직접화일의 구현
자료구조 전위,중위,후위 순회
[영상처리] 히스토그램 평활화 및 각종 영상처리 (칼라)
bmp Image 변환 프로그램 10가지 효과 적용가능
Mini C 어휘분석기(Scanner)
알고리즘-머지-최적이진검색-최단프림
자료구조와 알고리즘 BFS (INTRODUCTION TO ALGORITHMS)
[VRML][VRML 정의][VRML 특징][VRML 기능][VRML 표준][VRML 응용분야][VRML 전개 방향]VRML의...
[전자공학,졸업작품,졸작]atmega128 (AVR), 적외선(포토)센서를 이용한 자동문
그래픽스 , meshranddering
마이크로 프로세서 프로젝트 최종보고서
[C/C++] 간단한 파일 전송 프로그램
[C/C++] 스레드(Thread)를 활용한 간단한 채팅 프로그램
소개글