t1=t2=0;
N=N-1;
L=N-1;
for ( ; !empty(); i++) {
/* ta t1, t2 exoun tis theseis me tis
mikroteres syxnothtes */
t1=removee();
printf("t1=%d \n",t1);
getch();
t2=removee();
printf("t2=%d \n",t2);
getch();
printf("\narxizei h dhmiourgia twn dendrwn\n");
printf("\nDhmiourgia stoixeiou .........%d......(ftanei ws
to 44)\n",i);
dad[i] = 0;
printf("dad[%d]=%d \n",i,dad[i]);
getch();
dad[t1] = i;
printf("dad[%d]=%d \n",t1,dad[t1]);
getch();
dad[t2] = -i;
printf("dad[%d]=%d \n",t2,dad[t2]);
count[i] = count[t1] + count[t2];
printf("\nTo t1 kai t2 einai ta paidia tou dendrou\n
");
printf("To i einai h riza (pateras) tou dendrou\n ");
printf("kai ta count einai oi suxnothtes tous\n");
printf("t1=%d , t2=%d , i=%d , count[%d]=%d , count[%d]=%d ,
count[%d]=%d \n",
t1,t2,i,t1,count[t1],t2,count[t2],i,count[i]);
N=N+2;
if
(N==17){dad[N+1]=0;flag=1;aa[N+1]=aa[N];info[N+1]=info[N];p[N+1]=p[N];}
if (flag){flag=0;aa[N]=aa[N-1];info[N]=info[N-1];p[N]=p[N-1];}
N=N-2;
N=N+1;
if (!empty())
insert(count[i], i);
N=N-1;
if (i>30) printf("\nprosoxh meta to 30 de fainontai ola
ta apotelesmata\n\n");
for (j=0;j<=43;j++){
if (i<30) {
printf("\nO count exei tis syxnothtes olwn twn xarakthrwn
tou alfabhtoy\n");
printf("me 27o to space\n");
printf("O info exei tis xyxnothtes twn xarakthrwn pou den
einai 0\n");
printf("count[%d]=%d , info[%d]=%d ,
aa[%d]=%d\n",j,count[j],j,info[j],j,aa[j]);
getch();
}
}
}
printf("Edw parousiazontai oles oi rizes twn
korufwn\n");
for (i=0;i<=43;i++){
printf("dad[%d]=%d \n",i,dad[i]);
getch();
}
for (k = 0; k <=26 ; k++) {
i = 0;
x = 0;
j = 1;
if (count[k])
for (t=dad[k]; t; t=dad[t], j+=j, i++)
if (t < 0) {
x += j;
t = -t;
}
code[k] = x;
len[k] = i;
}
for (k=0;k<26;k++){
printf("k=%d , code[%d]=%d , len[%d]=%d
\n",k,k,code[k],k,len[k]);
}
/* for (j = 0; j < 26; j++)
for (i = len[index(a[j])]; i > 0; i--) {
cout << ( (code[index(a[j])] >> i-1) & 1);
printf("%b",cout);
} */
printf("\nEdw parousiazetai h telikh kwdikopoihsh\n");
printf("sp 0 ");bin(code[0],len[0]);printf("
%d",len[0]);
printf("\n");
for (j=1;j<=26;j++){
if ( (code[j]) || ( (!code[j]) && (count[j]!=0) ) ){
printf("%c %d
",j+96,j);bin(code[j],len[j]);printf("
%d",len[j]);
printf("\n");
}
}
getch();getch();
}