From 971e47727a0273850b368ef4e7e7a01dabb47c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A8=9A=E7=90=A6?= Date: Sat, 30 Apr 2022 13:10:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++++ .idea/TouGe-Huffman-Tree.iml | 2 + .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ SY1.cpp | 73 ++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/TouGe-Huffman-Tree.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 SY1.cpp diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/TouGe-Huffman-Tree.iml b/.idea/TouGe-Huffman-Tree.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/TouGe-Huffman-Tree.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1861faa --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SY1.cpp b/SY1.cpp new file mode 100644 index 0000000..e1edbfb --- /dev/null +++ b/SY1.cpp @@ -0,0 +1,73 @@ +// /Users/zhangzhiqi/Library/Mobile Documents/M6HJR9W95L~com~textasticapp~textastic/Documents/CLionProjects/TouGe-Huffman-Tree/SY1.cpp +// Copyright (c) 2022. +// @Time : 2022/4/30 13:9:13 +// @Author : 张稚琦 +// @Address: 湖北理工学院腾龙公寓 5620 +// @Email : zhang@zhang.mba / zhangzhiqi828@gmail.com / zhangzhiqi@lh83.onmicrosoft.com / 2272358828@qq.com +// @File : SY1.cpp +// @LastModified: 2022/4/30 下午1:07 +// @ProjectName : TouGe_Huffman_Tree + +# include +# include +# include +using namespace std; + + +typedef struct //define structure HuffmanTree +{ int weight; + int parent,lchild,rchild; +}HTNode,*HuffmanTree; + +typedef char ** HuffmanCode; + +void Select(HuffmanTree HT,int i,int &s1,int &s2) ;//选出HT树到i为止,权值最小且parent为0的2个节点 +void HuffmanTreeing(HuffmanTree &HT,int *w,int n);//构建哈夫曼树函数 + +void output(HuffmanTree HT,int m);//输出哈夫曼树 + +int main() +{ + HuffmanTree HT; + HuffmanCode HC; + int n,i; + int *w; + scanf("%d",&n); + w=(int *)malloc(n*sizeof(int)); + for(i=0;i0),构造赫夫曼树HT + /********** Begin **********/ + + + /********** End **********/ +} + + +void output(HuffmanTree HT,int m) +{ //输出哈夫曼树 + for(int i=1;i<=m;++i) + { + cout<<"HT["<