#include
<
stdio.h
>
#include < math.h >
#define TRUE 1
#define FALSE 0
int N; // 数据个数
int K; // 集合个数
int * CenterIndex; // 初始化质心数组的索引
double * Center; // 质心集合
double * CenterCopy; // 质心集合副本
double * AllData; // 数据集合
double ** Cluster; // 簇的集合
int * Top; // 集合中元素的个数,也会用作栈处理
// 随机生成k个数x(0<=x<=n-1)作为起始的质心集合
void CreateRandomArray( int n, int k, int * center)
{
int i = 0 ;
int j = 0 ;
srand( (unsigned)time( NULL ) );
for ( i = 0 ;i < k; ++ i) // 随机生成k个数
{
int a = rand() % n;
// 判重
for (j = 0 ;j < i;j ++ )
{
if (center[j] == a) // 重复
{
break ;
}
}
if (j >= i) // 如果不重复,加入
{
center[i] = a;
}
else
{
i -- ;
#include < math.h >
#define TRUE 1
#define FALSE 0
int N; // 数据个数
int K; // 集合个数
int * CenterIndex; // 初始化质心数组的索引
double * Center; // 质心集合
double * CenterCopy; // 质心集合副本
double * AllData; // 数据集合
double ** Cluster; // 簇的集合
int * Top; // 集合中元素的个数,也会用作栈处理
// 随机生成k个数x(0<=x<=n-1)作为起始的质心集合
void CreateRandomArray( int n, int k, int * center)
{
int i = 0 ;
int j = 0 ;
srand( (unsigned)time( NULL ) );
for ( i = 0 ;i < k; ++ i) // 随机生成k个数
{
int a = rand() % n;
// 判重
for (j = 0 ;j < i;j ++ )
{
if (center[j] == a) // 重复
{
break ;
}
}
if (j >= i) // 如果不重复,加入
{
center[i] = a;
}
else
{
i -- ;