馒头
考数据结构的好像
有一个建树的函数
__int64 __fastcall initHuffmanTree(void **a1)
{
__int64 v1; // rcx
__int64 v2; // rdx
char v4; // [rsp+27h] [rbp-9h]
int j; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]
*a1 = malloc(0x3C0ui64);
for ( i = 1; i <= 47; ++i )
{
v1 = (__int64)*a1 + 20 * i;
*(_DWORD *)(v1 + 16) = -1;
v2 = (__int64)*a1 + 20 * i;
*(_DWORD *)(v2 + 12) = *(_DWORD *)(v1 + 16);
*((_DWORD *)*a1 + 5 * i + 2) = *(_DWORD *)(v2 + 12);
}
puts("please input flag:");
for ( j = 1; j <= 24; ++j )
{
v4 = getchar();
*((_DWORD *)*a1 + 5 * j) = j;
*((_DWORD *)*a1 + 5 * j + 1) = v4;
}
return 1i64;
}
__int64 __fastcall creatHuffmanTree(_QWORD *a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx
int j; // [rsp+8h] [rbp-18h]
int v5; // [rsp+Ch] [rbp-14h]
int v6; // [rsp+10h] [rbp-10h]
int v7; // [rsp+14h] [rbp-Ch]
int v8; // [rsp+18h] [rbp-8h]
int i; // [rsp+1Ch] [rbp-4h]
if ( a2 > 1 )
{
for ( i = a2 + 1; ; ++i )
{
result = (unsigned int)(2 * a2);
if ( i >= (int)result )
break;
v8 = 0x7FFF;
v7 = -1;
v6 = 0x7FFF;
v5 = -1;
for ( j = 1; i > j; ++j )
{
if ( v8 > *(_DWORD *)(*a1 + 20i64 * j + 4) && *(_DWORD *)(*a1 + 20i64 * j + 8) == -1 )
{
v6 = v8;
v5 = v7;
v8 = *(_DWORD *)(*a1 + 20i64 * j + 4);
v7 = j;
}
else if ( v6 > *(_DWORD *)(*a1 + 20i64 * j + 4) && *(_DWORD *)(*a1 + 20i64 * j + 8) == -1 )
{
v6 = *(_DWORD *)(*a1 + 20i64 * j + 4);
v5 = j;
}
}
v3 = *a1 + 20i64 * v5;
*(_DWORD *)(v3 + 8) = i;
*(_DWORD *)(*a1 + 20i64 * v7 + 8) = *(_DWORD *)(v3 + 8);
*(_DWORD *)(*a1 + 20i64 * i + 12) = v7;
*(_DWORD *)(*a1 + 20i64 * i + 16) = v5;
*(_DWORD *)(*a1 + 20i64 * i + 4) = *(_DWORD *)(*a1 + 20i64 * v7 + 4) + *(_DWORD *)(*a1 + 20i64 * v5 + 4);
}
}
return result;
}
发现是用数组实现的哈夫曼树,不知道去学学。
有关于哈夫曼树的提示,还原哈夫曼树的节点
看一下别人的示意图.