|
- // /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 <stdio.h>
- # include <iostream>
- # include <string.h>
- 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;i<n;i++)
- {
- scanf("%d",&w[i]);
- }
- HuffmanTreeing( HT , w ,n );
- cout<<"哈夫曼树:"<<endl;
- output(HT,2*n-1);
- return 0;
- }
-
- void Select(HuffmanTree HT,int i,int &s1,int &s2)
- { //选出HT树到i为止,权值最小且parent为0的2个节点
- //s1 is the least of HT[].weight
- //s2 is the second least of HT[].weight
- /********** Begin **********/
-
- /********** End **********/
- }
-
-
- void HuffmanTreeing(HuffmanTree &HT,int *w,int n) //构建哈夫曼树函数
- { // w存放n个字符的权值(均>0),构造赫夫曼树HT
- /********** Begin **********/
-
-
- /********** End **********/
- }
-
-
- void output(HuffmanTree HT,int m)
- { //输出哈夫曼树
- for(int i=1;i<=m;++i)
- {
- cout<<"HT["<<i<<"] ="<<HT[i].weight<<"\t"<<HT[i]. parent<<"\t";
- cout<<"\t" <<HT[i]. lchild <<"\t" <<HT[i]. rchild<<endl;
- }
- }
|