摘要:
画的类图如下:分为两个类kMeans和pointClass类,kMeans两个成员变量:节点总个数和最终聚类个数。pointClass类包含结构体point。具体代码如下:kMeans.hclass kMeans{protected: int numOfPoint, numOfCenter;public: kMeans(); void k_means();};View Code kMeans.cpp#include "kMeans.h"#include "point.h"#include using namespace std;kMeans::kMean 阅读全文
摘要:
首先画出k_means算法的流程图:具体代码,C++实现:#include #include #include #include using namespace std;const int N = 10000;typedef struct { double x1,x2; int flag;}oneNode;oneNode node[N];int k,n;void DataInput();void SetInitial(oneNode *p,oneNode *q);void SetQzero(oneNode &qi);bool GetExist(int xm,int *sb,int .. 阅读全文