alg.cpp
来自「分级聚类算法」· C++ 代码 · 共 63 行
CPP
63 行
// 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 + =
减小字号Ctrl + -
显示快捷键?