Home > database >  Huffman tree data structure
Huffman tree data structure

Time:10-08

Choose when the minimum value has node
The select function, can't write 3

CodePudding user response:

The idea is as follows:
(1) hypothesis has now been obtained weights of a minimum of two nodes location min_first=min_second=0, a weight of min1=min2=10000 (a large number of optional)
(2) traverses the weight array, comparing every time update the weights of the smallest two node location and weight
The code is as follows:
Int min_first min_second, min1, min2;
Min_first=min_second=0;
Min1=min2=10000;
For (int I=1; i<=n; I++)
{
If (HT [I]. Parent==0)
{
If (HT [I] weight{
Min2=min1;
Min_second=min_first;
Min1=HT [I]. Weight;
Min_first=I;
}
Else if (HT [I] weight{
Min2=HT [I]. Weight;
Min_second=I;
}
}
}
  • Related