⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.cpp

📁 用C++编写的哈弗曼树的源代码,方便C语言及C++初学者学习交流
💻 CPP
字号:
#include"head.h"
void select(Huffmantree &HT,int n,int *s1,int *s2)
{//选择结点中最小和次小的结点
	int i=0;
	for(i=1;i<=n;i++)
	{//在未选过的结点中任选一个节点作为假设的最小值
		if(HT[i].parent==0)
		{
		   *s1=i;break;
		}
	}
	for(i=1;i<=n;i++)
	{//在HT中寻找未选节点权值更小的值
		if(HT[i].parent!=0) 
			continue;
		else if(HT[*s1].weight>HT[i].weight)
			*s1=i;
	}
	for(i=1;i<=n;i++)
	{
		if(i!=*s1&&HT[i].parent==0)
		{//选择一个假设权值为最小的节点,排除*s1和已选过的节点
			*s2=i;break;
		}
	}
	for(i=1;i<=n;i++)
	{//在HT中寻找未选节点权值更小的值
		if(i==*s1||HT[i].parent!=0)
			continue;
		else if(HT[*s2].weight>HT[i].weight)
			*s2=i;
	}
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -