Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab013
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
DS Lab Group
实验项目模板
Lab013
提交
194e67b8
提交
194e67b8
8月 15, 2019
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
a5eed84a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
19 行删除
+17
-19
HuffmanTree.h
HuffmanTree.h
+8
-7
main.c
main.c
+9
-12
没有找到文件。
HuffmanTree.h
浏览文件 @
194e67b8
#ifndef HUFFMANTREE_H_
#ifndef HUFFMANTREE_H_
#define HUFFMANTREE_H_
#define HUFFMANTREE_H_
//
//
// Include the C standard library header file here
// Include the C standard library header file here
//
//
#include <stdio.h>
#include <stdio.h>
//
//
// Other header files are included here
// Other header files are included here
//
//
//
//
// Define the data structure here
// Define the data structure here
//
//
...
@@ -21,16 +18,20 @@
...
@@ -21,16 +18,20 @@
#define MAXVALUE 1000 // Define the maximum value
#define MAXVALUE 1000 // Define the maximum value
// Node structure
// Node structure
typedef
struct
HtNode
{
typedef
struct
HtNode
{
int
Weight
;
// The node weight
int
Weight
;
// The node weight
int
parent
,
lchild
,
rchild
;
// The parent and the left and right child are subscripts in the array
// The parent and the left and right child are subscripts in the array
int
parent
,
lchild
,
rchild
;
}
HtNode
;
}
HtNode
;
// The structure of a Huffman tree
// The structure of a Huffman tree
typedef
struct
_HtTree
{
typedef
struct
_HtTree
{
int
Count
;
// Number of leaf nodes
int
Count
;
// Number of leaf nodes
int
Root
;
// The index of the Huffman root node in the array
int
Root
;
// The index of the Huffman root node in the array
struct
HtNode
*
HtArray
;
// The subscript of the Huffman root in an array of 2*Count-1 nodes
// The subscript of the Huffman root in an array of 2*Count-1 nodes
struct
HtNode
*
HtArray
;
}
HtTree
,
*
PHtTree
;
}
HtTree
,
*
PHtTree
;
//
//
...
...
main.c
浏览文件 @
194e67b8
#include "HuffmanTree.h"
#include "HuffmanTree.h"
#include <stdlib.h>
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
...
@@ -17,7 +18,7 @@ int main(int argc, char* argv[])
...
@@ -17,7 +18,7 @@ int main(int argc, char* argv[])
PHtTree
pTree
=
(
PHtTree
)
malloc
(
sizeof
(
HtTree
));
PHtTree
pTree
=
(
PHtTree
)
malloc
(
sizeof
(
HtTree
));
pTree
->
HtArray
=
(
HtNode
*
)
malloc
(
sizeof
(
HtNode
)
*
HuffmanLength
);
pTree
->
HtArray
=
(
HtNode
*
)
malloc
(
sizeof
(
HtNode
)
*
HuffmanLength
);
for
(
i
=
0
;
i
<
HuffmanLength
;
i
++
)
for
(
i
=
0
;
i
<
HuffmanLength
;
i
++
)
{
{
pTree
->
HtArray
[
i
].
lchild
=
-
1
;
pTree
->
HtArray
[
i
].
lchild
=
-
1
;
pTree
->
HtArray
[
i
].
rchild
=
-
1
;
pTree
->
HtArray
[
i
].
rchild
=
-
1
;
...
@@ -54,7 +55,8 @@ returned value:
...
@@ -54,7 +55,8 @@ returned value:
*/
*/
PHtTree
HuffmanTree
(
PHtTree
pTree
,
int
Count
)
PHtTree
HuffmanTree
(
PHtTree
pTree
,
int
Count
)
{
{
int
i
,
j
;
// Cursor, which is mainly used to find the index of the smallest node and the second smallest node
// Cursor, which is mainly used to find the index of the smallest node and the second smallest node
int
i
,
j
;
int
Index1
,
Index2
;
// Holds the subscript of the smallest and subsmallest nodes
int
Index1
,
Index2
;
// Holds the subscript of the smallest and subsmallest nodes
int
Number1
,
Number2
;
// Store minimum and sub - small node weights
int
Number1
,
Number2
;
// Store minimum and sub - small node weights
...
@@ -69,17 +71,12 @@ void OutputResult(PHtTree pTree, int Length)
...
@@ -69,17 +71,12 @@ void OutputResult(PHtTree pTree, int Length)
{
{
int
i
;
int
i
;
printf
(
"subscript
\t
weight
\t
parent
\t
lchild
\t
rchild
\n
"
);
printf
(
"subscript
\t
weight
\t
parent
\t
lchild
\t
rchild
\n
"
);
for
(
i
=
0
;
i
<
Length
;
i
++
)
for
(
i
=
0
;
i
<
Length
;
i
++
)
{
{
printf
(
"%d"
,
i
);
printf
(
"%d"
,
i
);
printf
(
"
\t\t
%d"
,
pTree
->
HtArray
[
i
].
Weight
);
printf
(
"
\t\t
%d"
,
pTree
->
HtArray
[
i
].
Weight
);
printf
(
"
\t\t
%d"
,
pTree
->
HtArray
[
i
].
parent
);
printf
(
"
\t\t
%d"
,
pTree
->
HtArray
[
i
].
parent
);
printf
(
"
\t\t
%d"
,
pTree
->
HtArray
[
i
].
lchild
);
printf
(
"
\t\t
%d"
,
pTree
->
HtArray
[
i
].
lchild
);
printf
(
"
\t\t
%d
\n
"
,
pTree
->
HtArray
[
i
].
rchild
);
printf
(
"
\t\t
%d
\n
"
,
pTree
->
HtArray
[
i
].
rchild
);
}
}
}
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论