mình đã có code về thuật toán này nhưng không biết chuyển sang thuật toán như thế nào.Mong được sự giúp đỡ của mọi người.Đây là code của mình

file thuvien.h
#ifndef thu_vien_h
#define thu_vien_h
#include <fstream.h>
#include <string.h>
#include <math.h>
char * ChuyenSoThanhXauNhiPhan(int a, int z)
{
char * kq = new char[z+1];
kq[z] = '\0';
for(int i=0; i<z; i++)
kq[i] = '0';
while (a>0)
{
int r = a%2;
kq[z-1] = '0' + r;
z--;
a = a/2;
}
return kq;
}

int ChuyenXauThanhSo(const char * x)
{
int kq = 0;
int l = strlen(x);
for (int i=l; i>0; i--)
{
kq += (x[i-1]-'0') * pow(2, l-i);
}
return kq;
}

void ChuyenFileGoc(const char * fDauVao, const char * fDauRa)
{
ifstream fin(fDauVao);
ofstream fout(fDauRa);

char ch;
while (fin.get(ch))
{
int vt = ch;
fout<<ChuyenSoThanhXauNhiPhan(vt, 8);
}

fin.close();
fout.close();

}

void ChuyenFileNhiPhanGoc(const char * fDauVao, const char * fDauRa)
{
ifstream fin(fDauVao);
ofstream fout(fDauRa);

char a[10];
while(fin.getline(a, 9))
{
//a[8]='\0';
int so = ChuyenXauThanhSo(a);
fout<<(char)so;
}

fin.close();
fout.close();
}

#endif

file man.cpp

#include <iostream.h>
#include "ThuVien.h"
#include <string.h>
struct Node
{
char ch;
int sl;
Node *ct;
Node *cp;
Node *cha;
};

Node *g = 0;
char kq[100];
int lkq = 0;

bool MaHuffman(char ch, Node *g);
void main()
{
int a[256];
for(int i = 0; i<256; i++)
a[i] = 0;
ifstream fin("D:\\FileGoc.txt");

char ch;
while (fin.get(ch))
{
a[ch] ++;
}
fin.close();

int dem =0;
for(i=0; i<256; i++)
if (a[i]!=0)
{
//cout<<(char)i<<" : "<<a[i]<<endl;
dem++;
}

Node *ds[100];// = new Node[dem];
int j =0;
for(i=0; i<256; i++)
if (a[i]!=0)
{
Node *t =new Node;
t->ch = (char)i;
t->ct = 0;
t->cp = 0;
t->sl = a[i];
t->cha = 0;
ds[j++] = t;

}
for (i=0; i<dem-1; i++)
for(j=i+1; j<dem; j++)
if (ds[i]->sl < ds[j]->sl)
{
Node *t = ds[i];
ds[i]=ds[j];
ds[j] = t;
}

g = new Node;
g->ct = ds[dem-2];
ds[dem-2]->cha = g;
g->cp = ds[dem-1];
ds[dem-1]->cha = g;
for(i = dem -2; i>0; i--)
{
Node *t = new Node;
t->cha = 0;
t->ct = ds[i-1];
ds[i-1]->cha = t;
t->cp = g;
g->cha = t;
g = t;
}

ifstream fi("D:\\FileHuffman.txt");
ofstream fo("D:\\GiaiHuffman.txt");

Node *h = g;
ch;
while (fi.get(ch))
{
if (h->ct==0)
{
fo<<h->ch;
h = g;
}
if(ch == '0')
h=h->ct;
else
h = h->cp;
}

fi.close();
fo.close();

//ChuyenFileGoc("D:\\FileGoc.txt", "D:\\FileNhiPhanGoc.txt");
//ChuyenFileNhiPhanGoc("D:\\FileNhiPhanGoc.txt", "D:\\SauChuyen.txt");
/*int a[256];
for(int i = 0; i<256; i++)
a[i] = 0;
ifstream fin("D:\\FileGoc.txt");

char ch;
while (fin.get(ch))
{
a[ch] ++;
}
fin.close();

int dem =0;
for(i=0; i<256; i++)
if (a[i]!=0)
{
//cout<<(char)i<<" : "<<a[i]<<endl;
dem++;
}

Node *ds[100];// = new Node[dem];
int j =0;
for(i=0; i<256; i++)
if (a[i]!=0)
{
Node *t =new Node;
t->ch = (char)i;
t->ct = 0;
t->cp = 0;
t->sl = a[i];
t->cha = 0;
ds[j++] = t;

}
for (i=0; i<dem-1; i++)
for(j=i+1; j<dem; j++)
if (ds[i]->sl < ds[j]->sl)
{
Node *t = ds[i];
ds[i]=ds[j];
ds[j] = t;
}

g = new Node;
g->ct = ds[dem-2];
ds[dem-2]->cha = g;
g->cp = ds[dem-1];
ds[dem-1]->cha = g;
for(i = dem -2; i>0; i--)
{
Node *t = new Node;
t->cha = 0;
t->ct = ds[i-1];
ds[i-1]->cha = t;
t->cp = g;
g->cha = t;
g = t;
}

ifstream fin1("D:\\FileGoc.txt");
ofstream fout1("D:\\FileHuffman.txt");
//char ch;
while (fin1.get(ch))
{
lkq = 0;
MaHuffman(ch, g);
fout1<<kq;
}
fin1.close();
fout1.close();*/
}

bool MaHuffman(char ch, Node *g)
{
if(g!=0)
{
if (ch==g->ch)
{
kq[lkq] = '\0';
return true;
}
else
{
kq[lkq] = '0';
lkq++;
bool a = MaHuffman(ch, g->ct);
if (a)
return true;
lkq--;
kq[lkq] = '1';
lkq++;
bool b = MaHuffman(ch, g->cp);
if (b)
return true;
lkq--;
//return MaHuffman(ch, g->ct) || MaHuffman(ch, g->cp);
}
}
else
{
return false;
}


/*else
{
kq[lkq] = '\0';
return kq;

}*/



/*if (g->ch == ch)
{
kq[lkq] = '\0';
return kq;
}
else
{
if(g->ct !=0)
{
kq[lkq] = '0';
lkq++;
MaHuffman(ch, g->ct);
lkq--;
if (g->cp !=0)
{
kq[lkq] = '1';
lkq++;
MaHuffman(ch, g->cp);
lkq--;
}
}
else if (g->cp!=0)
{
kq[lkq] = '1';
lkq++;
MaHuffman(ch, g->cp);
lkq--;
}
else
return "";
}*/
}