voidCreatHuffmanTree(int n)// N leaf nodes. { if (n <= 1) { printf("None."); } else { int i, weight; int m = 2 * n - 1; int s1 = 0, s2 = 0; HTNode* HT = (HTNode*)malloc(20 * sizeof(HTNode)); // See HT as an array. if (HT) { for (i = 1; i <= m; i++) // Initialize the array. { HT[i].lchild = HT[i].rchild = HT[i].parent = 0; } for (i = 1; i <= n; i++) { printf("Input weight:\n"); scanf_s("%d", &weight); HT[i].weight = weight; // Value assignment. } for (i = n + 1; i <= m; i++) { Select(HT, i - 1, m, &s1, &s2); // Funtion Select chooses the smallest two elements. HT[s1].parent = i; HT[s2].parent = i; HT[i].lchild = s1; HT[i].rchild = s2; HT[i].weight = HT[s1].weight + HT[s2].weight; } } } }