编辑代码

#include <stdio.h>
#include <stdlib.h>
#include<assert.h> 

typedef struct{
    int Weight;
    int parent;
    int lchild;
    int rchild;
}HufMan;

int HufManFindmin(HufMan* hf){
    int i = 0;
    int idx;
    int min = 1000;
    while(hf[++i].Weight!=0){
        (hf[i].parent == 0)?
        min = (min>hf[i].Weight?(idx = i,hf[i].Weight):min)
        :0;        
        // printf("%d、",(min>hf[i].Weight?(hf[i].Weight));
    }
    return idx;
}

int main () {
    HufMan hf[50];
    memset(hf,0,sizeof(hf));
    for (int i = 1 ; i <= 25; i++){
        hf[i].Weight = rand()%100;
        printf("%d ",hf[i].Weight);
    }
    hf[0].Weight = 26;
    for(1;hf[0].Weight <= 50;hf[0].Weight++){
        int c = hf[0].Weight;
        int child = HufManFindmin(hf);
        hf[child].parent = c;
        // hf[c].parent = 0;
        hf[c].lchild = 0;
        // hf[c].lchild = child;
        // hf[c].Weight += hf[child].Weight;

        // child = HufManFindmin(hf);
        // hf[child].parent = hf[0].Weight;
        // hf[c].rchild = child;
        // hf[c].Weight += hf[child].Weight;
    }
    
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
	printf("Hello JSRUN!   \n\n         - from C .");
	return 0;
}