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

📄 alg.cpp

📁 分级聚类算法
💻 CPP
字号:
// ALG.cpp: implementation of the ALG class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ALG.h"

BOOL GradeCluser(VECTORLIST &pnts, int n)//pnts:点列表   n:最终数目
{
	int sz = pnts.size();
	if(n>sz)
		return FALSE;

	if(n==sz)
		return TRUE;

	int dist=GetDis(pnts[0][0], pnts[1][0]);
	int p1=0, p2=1;

	for(int i=0; i<sz-1; i++)
	{
		for(int j=i+1; j<sz; j++)
		{
			int temp=GetDis(pnts[i][0], pnts[j][0]);
			if(dist>temp)
			{
				dist=temp;
				p1=i;
				p2=j;
			}
		}
	}
	
	PNTVECTOR newvector;
	newvector.push_back(GetCenter(pnts[p1][0], pnts[p2][0]));

	PNTVECTOR::iterator it;
	if(pnts[p1].size()==1)
		it=pnts[p1].begin();
	else
		it=pnts[p1].begin()+1;

	for(; it!=pnts[p1].end(); it++)
	{
		newvector.push_back(*it);
	}

	if(pnts[p2].size()==1)
		it=pnts[p2].begin();
	else
		it=pnts[p2].begin()+1;

	for(; it!=pnts[p2].end(); it++)
	{
		newvector.push_back(*it);
	}

	pnts.erase(pnts.begin()+p1);
	pnts.erase(pnts.begin()+p2-1);
	pnts.push_back(newvector);

	return GradeCluser(pnts, n);
}

⌨️ 快捷键说明

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