哈夫曼树循环寻找最小下标无法找到T??

哈夫曼树循环寻找最小下标无法找到'T'。

The Chinese official said he viewed the Trump Presidency not as an aberration but as the product of a failing political system.This jibes with other accounts.The Chinese leadership believes that the United States, and Western democracies in general, haven't risen to the challenge of a globalized economy, which necessitates big changes in production patterns, as well as major upgrades in education and public infrastructure. In Trump and Trumpism, the Chinese see an inevitable backlash to this failure.

以下是主要代码,编码之后发现只有‘T’编不出来。

//判断字符是否重复出现过
bool JudgeWords(char ch, int j)
{ 
    int i = 0;
    for (i = 0; i < j; i++)//重复出现
    {
        if(HT[i].data==ch)
            return true;//1
    }
    return false;//0
}
//计算各个字符个数以及频率
int CountWords(char* s)
{
    int j = 0,Total=0;
    for (int i = 0;s[i]!='\0'; i++)
    {
        char ch = s[i];
        if (!JudgeWords(ch, j))//没有重复
        {
            HT[j].data = ch;
            HT[j].rate = 1;//出现频率
            j++;
        }
        else//有重复
        {
            for (int k = 0; k < j; k++)
            {
                if (HT[k].data == ch)
                    HT[k].rate++;
            }
        }
    }
    for (int q = 0; q < j; q++)//计算总字符个数
    {
        Total = HT[q].rate + Total;
    }
    cout << "该篇文章不同的字符的个数为:" << j << endl;
    cout << "该篇文章总字符的个数为:" << Total << endl;
    cout << endl;
    for (int i = 0; i < j; i++)
    {
        cout << HT[i].data << "的频率为:" << HT[i].rate << endl;
    }
    return j;
}
void InputWeight(HuffmanTree*& T, int len, int& n1, int& n2)
{
    int min1 = 32767, min2 = 32767;//先赋最大值,不影响后面运行
    for (int i = 1; i <= len; i++)//寻找第一个最小值
    {
        if (T[i]->parent == 0 && T[i]->weight <= min1)
        {
            min1 = T[i]->weight;
            n1 = i;//记录是第几个结点,以免后面重复寻找
        }
    }
    //cout <<"min1:"<< min1 << endl;
    int tmp = T[n1]->weight;
    T[n1]->weight = 32767;//防止后面重复查找
    for (int i = 1; i <= len; i++)
    {
        if (T[i]->parent == 0 && T[i]->weight <= min2)
        {
            min2 = T[i]->weight;
            n2 = i;
        }
        
    }
    //cout << "min2: "<< min2 << endl;

    T[n1]->weight = tmp;//恢复原来的值 
}
//构造哈夫曼树,T[m-1]为根节点
void CreateHuffmanTree(HuffmanTree*& T,int num1)//num1为叶子结点
{
    int n1, n2;//n1,n2为任意两个结点
    if (n <=1)    /////////
        return;
    //m = 2 * n - 1;//m为结点个数
    T = new HuffmanTree[m + 1];//动态创建,范围[1,m]=[0,m-1]
    for (int i = 1; i <= m; i++)//初始化//////////
    {
        T[i]->parent = NULL; 
        T[i]->rchild = NULL; 
        T[i]->lchild = NULL;
    }    
    for (int i = 0; i <=n; i++)//////////
    {
        T[i]->weight = HT[i].rate;//注意:这两个在不同的结构体中
        cout << HT[i].data << ":" << T[i]->weight<for (int i = n + 1; i <= m; i++)//建第n+1个结点为父结点,循环一次建一次
    {
        InputWeight(T, i -1, n1, n2);
        T[n1]->parent = i;
        T[n2]->parent = i;//再次调用InputWeight函数时不会重复找寻
        //T[i]->parent = 0;//新结点的父结点初始化
        T[i]->lchild = n1;
        T[i]->rchild = n2;//T[i]为返回的两个权值最小的结点的父结点
        T[i]->weight = T[n1]->weight + T[n2]->weight;
    }
}

void CharSetHuffmanEnCoding(HuffmanTree*& T, int num1, const string& codingData)
{
    if (T[num1]->rchild == 0 && T[num1]->lchild == 0) {
        cout << HT[num1].data << " : " << codingData << endl;
        T[num1]->word = codingData;
        //string sen = T[num1]->word;
    }
    else {
        string data = codingData + "0";
        CharSetHuffmanEnCoding(T, T[num1]->lchild, codingData + "0");
        CharSetHuffmanEnCoding(T, T[num1]->rchild, codingData + "1");
    }
}