问题遇到的现象和发生背景 可以输入初始数据,但是不出结果
问题相关代码,请勿粘贴截图
[](
```c
#include<stdio.h>
#include<stdlib.h>
typedef struct max
{
int a[8];
int size;
int sum;
}qq,qw;
typedef struct TreeNode HuffmanTree;
struct TreeNode{
int Weight;
HuffmanTree Left, Right;
};
int main()
{
qq h,u;
int ii,b,i;
int d[8],ll[8];
int we,ww;
char ss[58];
void make(qq z);
void num(int s[],char c[]);
int mindel(qq j);
qq minmake(qq j);
HuffmanTree Huffman(qq H);
void bianma(HuffmanTree t,int a[]);
HuffmanTree gh;
printf("请输入58个字符(字符限制为:a,s,d,f,g,h,j,k),以#结束");
for(i=0;i<=10;i++)
{scanf("%c",&ss[i]);
}
for(i=0;i<=10;i++)
printf("%c",ss[i]);
make(u);
num(u->a,ss);
for(ii=1;ii<=7;ii++)
{
d[ii]=u->a[ii];
ll[ii]=u->a[ii];
printf("%d",u->a[ii]);
}
minmake(u);
gh=Huffman(u);
bianma(gh,d);
return 0;
}
void make(qq z)
{
z->size=7;
z->sum=20;
z=(qq)malloc(sizeof(qw));
z->a[0]=59;
}
int mindel(qq j)
{
int parent,child,i;
int minItem, temp;
if (j==NULL) {
printf("最小堆已为空");
return;
}
minItem =j->a[1];
temp=j->a[j->size--];
for(parent=1;parent2<=j->size;parent=child)
{child=parent2;
if( (child!= j->size) && (j->a[child] > j->a[child+1]) )
child++;
if( temp <= j->a[child] ) break;
else
j->a[parent] = j->a[child];
}
j->a[parent] = temp;
return minItem;
}
qq minmake(qq j)
{
int parent,child,i;
int temp;
for(i=j->size/2;i>0;i--)
{temp=j->a[i];
for(parent=i;parent2<=j->size;parent=child)
{child=parent2;
if( (child!= j->size) && (j->a[child] > j->a[child+1]) )
child++;
if( temp <= j->a[child] ) break;
else
j->a[parent] = j->a[child];
}
j->a[parent] = temp;
}
return j;
}
void num(int s[],char c[])
{int i;
int b=0;
s[0]=59;
for(i=0;i<=57;i++)
{if(c[i]=='a')
b++;
}
s[1]=b;
printf("a的个数:%d\n",b);
b=0;
for(i=0;i<=57;i++)
{if(c[i]=='s')
b++;
}
s[2]=b;
printf("s的个数:%d\n",b);
b=0;
for(i=0;i<=57;i++)
{if(c[i]=='d')
b++;
}
s[3]=b;
printf("d的个数:%d\n",b);
b=0;
for(i=0;i<=57;i++)
{if(c[i]=='f')
b++;
}
s[4]=b;
printf("f的个数:%d\n",b);
b=0;
for(i=0;i<=57;i++)
{if(c[i]=='g')
b++;
}
s[5]=b;
printf("g的个数:%d\n",b);
b=0;
for(i=0;i<=57;i++)
{if(c[i]=='h')
b++;
}
s[6]=b;
printf("h的个数:%d\n",b);
b=0;
for(i=0;i<=57;i++)
{if(c[i]=='j')
b++;
}
s[7]=b;
printf("j的个数:%d\n",b);
return s;
}
HuffmanTree Huffman(qq H)
{ int mindel(qq j);
void Insert(qq x,int y);
int i;
HuffmanTree T;
for (i = 1; i < H->size; i++) {
T = (HuffmanTree)malloc( sizeof( struct TreeNode) );
T->Left->Weight=mindel(H);
T->Right->Weight=mindel(H);
T->Weight = T->Left->Weight+T->Right->Weight;
Insert(H,T->Weight);
}
T->Weight= mindel(H);
return T;}
void Insert(qq x,int y)
{int i;
if(x->sum==x->size)
{
printf("最小堆已满");
return;}
i = ++x->size;
for ( ; x->a[i/2]>y; i/=2 )
x->a[i] = x->a[i/2];
x->a[i] = y;
}
void bianma(HuffmanTree t,int a[])
{int i,j;
for(i=1;i<=8;i++)
{
printf("%c的编码为:",a[i]);
if(t->Weight==a[i])
break;
if(t==NULL) break;
printf("1");
bianma(t->Left,a);
printf("0");
bianma(t->Right,a);
}
}
```)
运行结果及报错内容
我的解答思路和尝试过的方法
我试过一步步调试,他出结果,但是一整体运行,就啥也没有了