浏览代码

开始任务

master
张稚琦 2 年前
父节点
当前提交
971e47727a
共有 5 个文件被更改,包括 97 次插入0 次删除
  1. +8
    -0
      .idea/.gitignore
  2. +2
    -0
      .idea/TouGe-Huffman-Tree.iml
  3. +8
    -0
      .idea/modules.xml
  4. +6
    -0
      .idea/vcs.xml
  5. +73
    -0
      SY1.cpp

+ 8
- 0
.idea/.gitignore 查看文件

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

+ 2
- 0
.idea/TouGe-Huffman-Tree.iml 查看文件

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

+ 8
- 0
.idea/modules.xml 查看文件

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/TouGe-Huffman-Tree.iml" filepath="$PROJECT_DIR$/.idea/TouGe-Huffman-Tree.iml" />
</modules>
</component>
</project>

+ 6
- 0
.idea/vcs.xml 查看文件

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 73
- 0
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 <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;
}
}

正在加载...
取消
保存