Go to the source code of this file.
Functions | |
| HuffTree * | build_tree (List &tmplist) |
|
|
Definition at line 5 of file HuffBld.hpp. Referenced by main().
00006 {
00007 HuffTree* temp1;
00008 HuffTree* temp2;
00009 HuffTree* temp3;
00010 LettFreq* tempnode;
00011
00012 for( tmplist.setPos(1); tmplist.isInList(); tmplist.setPos(1) )
00013 {
00014 // While at least two items left
00015 tmplist.setFirst();
00016 temp1 = tmplist.remove();
00017 temp2 = tmplist.remove();
00018 tempnode = new LettFreq( temp1->weight() + temp2->weight() );
00019 temp3 = new HuffTree( tempnode, temp1, temp2 );
00020
00021 // return to the list in sorted order
00022 for( tmplist.setFirst(); tmplist.isInList(); tmplist.next() )
00023 {
00024 if ( temp3->weight() <= tmplist.currValue()->weight() )
00025 {
00026 tmplist.insert( temp3 ); // Put in list
00027 break;
00028 }
00029 }
00030
00031 if ( !tmplist.isInList() ) // Its the heaviest value
00032 {
00033 tmplist.append(temp3);
00034 }
00035 }
00036
00037 tmplist.setFirst(); // Tree now only element on list
00038 return tmplist.remove(); // Return the tree
00039 }
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001