哈夫曼树的创建方法(一个指针)
```c
HuffmanCode* readHuffmanCodesFromFile ( const char * filename, int numCodes) {
FILE* file = fopen ( filename, "r" ) ;
if ( file == NULL ) {
perror ( "无法打开文件" ) ;
exit ( 1 ) ;
}
const int maxLines = 1000 ;
HuffmanCode* huffmanCodes = ( HuffmanCode* ) malloc ( maxLines * sizeof ( HuffmanCode) ) ;
char line[ 100 ] ;
numCodes = 0 ;
while ( fgets ( line, sizeof ( line) , file) != NULL ) {
if ( numCodes >= maxLines) {
fprintf ( stderr , "超过编码储存数量。\n" ) ;
fclose ( file) ;
free ( huffmanCodes) ;
exit ( 1 ) ;
}
char character;
char code[ 100 ] ;
if ( sscanf ( line, "%c: %s" , & character, code) == 2 ) {
huffmanCodes[ numCodes] . character = character;
huffmanCodes[ numCodes] . code = strdup ( code) ;
( numCodes) ++ ;
}
}
fclose ( file) ;
return huffmanCodes;
}
### 调用方法
```c
BiTNode *root = buildHuffmanTree(symbols, frequencies, size);
双重结构指针构造方法
luxian * * create ( char * path[ ] , char * time[ ] , char * starPath[ ] , char * endPath[ ] , char * chengyuan[ ] , int flightNum, int already, int totle)
{
luxian * * root = ( luxian * * ) malloc ( sizeof ( luxian * ) ) ;
for ( int i = 0 ; i < flightNum; i++ )
{
root[ i] = new luxian;
InitQueue ( root[ i] -> feiji-> remainWait) ;
}
for ( int i = 0 ; i < flightNum; i++ )
{
InitQueue ( root[ i] -> feiji-> remainWait) ;
root[ i] -> path = path[ i] ;
root[ i] -> rutine = time[ i] ;
root[ i] -> Star = starPath[ i] ;
root[ i] -> End = endPath[ i] ;
root[ i] -> feiji-> chengyuan = chengyuan[ i] ;
root[ i] -> feiji-> already = already;
root[ i] -> feiji-> totle = totle;
root[ i] -> feiji-> left = root[ i] -> feiji-> totle - root[ i] -> feiji-> already;
}
return root;
}
调用方法
```c
int flightNum = 2 ;
int num = 1 ;
int already = 1 ;
int totle = 2 ;
char ch;
luxian * * hangxian;
char * path[ 2 ] = { "aToz" , "sTox" } ;
char * time[ 5 ] = { "nine to twelevels" , "twelevels to pmtwo" , "pmtwo to pm4" } ;
char * starPath[ 4 ] = { "a" , "s" , "d" , "f" } ;
char * endPath[ 5 ] = { "z" , "x" , "c" , "v" } ;
char * chengwurenyuan[ 2 ] = { "hong" , "zhang" } ;
char name[ 20 ] ;
char * name1;
hangxian = create ( path, time, starPath, endPath, chengwurenyuan, flightNum, already, totle) ;