Tree/HuffmanTree.c
int* selectMin(HFTree* T) {
    int min = 10000;
    int secondMin = 10000;
    int minIndex;
    int secondIndex;
    for (int i = 0; i < T -> length; i++) {
        if (T -> data[i].parent == 0) {
            if (T -> data[i].weight < min) {
                min = T -> data[i].weight;
                minIndex = i;
            }
        }
    }
    for (int i = 0; i < T -> length; i++) {
        if (T -> data[i].parent == 0 && i != minIndex) {
            if (T -> data[i].weight < secondMin) {
                secondMin = T -> data[i].weight;
                secondIndex = i;
            }
        }
    }
    int* res = (int*)malloc(sizeof(int)* 2);
    res[0] = minIndex;
    res[1] = secondIndex;
    return res;
}
/**
 * select the min node from the node sequence
 * @param T the pointer of huffman tree
 * @return the index of min node
 */
select the min node from the node sequence
@param T the pointer of huffman tree
@return the index of min node
select the min node from the node sequence @param T the pointer of huffman tree @return the index of min node
int* selectMin(HFTree* T) {
    int min = 10000;
    int secondMin = 10000;
    int minIndex;
    int secondIndex;
    for (int i = 0; i < T -> length; i++) {
        if (T -> data[i].parent == 0) {
            if (T -> data[i].weight < min) {
                min = T -> data[i].weight;
                minIndex = i;
            }
        }
    }
    for (int i = 0; i < T -> length; i++) {
        if (T -> data[i].parent == 0 && i != minIndex) {
            if (T -> data[i].weight < secondMin) {
                secondMin = T -> data[i].weight;
                secondIndex = i;
            }
        }
    }
    int* res = (int*)malloc(sizeof(int)* 2);
    res[0] = minIndex;
    res[1] = secondIndex;
    return res;
}
int * selectMin ( HFTree * T ) { int min = 10000 ; int secondMin = 10000 ; int minIndex ; int secondIndex ; for ( int i = 0 ; i < T -> length ; i ++ ) { if ( T -> data [ i ] . parent == 0 ) { if ( T -> data [ i ] . weight < min ) { min = T -> data [ i ] . weight ; minIndex = i ; } } } for ( int i = 0 ; i < T -> length ; i ++ ) { if ( T -> data [ i ] . parent == 0 && i != minIndex ) { if ( T -> data [ i ] . weight < secondMin ) { secondMin = T -> data [ i ] . weight ; secondIndex = i ; } } } int * res = ( int * ) malloc ( sizeof ( int ) * 2 ) ; res [ 0 ] = minIndex ; res [ 1 ] = secondIndex ; return res ; }
select the min node from the node sequence
 @param T the pointer of huffman tree
 @return the index of min node
select the min node from the node sequence @param T the pointer of huffman tree @return the index of min node