Example #1
0
void Kmeans_ReplaceCenter(Node** ClusterList, Node** CandidateList, Node* candidateNode){
	//클러스터 값, 즉 초기 중심 센터 값을 현재 후보 카테고리에 삽입된 클러스터와 교체)
	//Current는 Cluster에 다시 넣고, candidateNode가 CandidateList(Sample)에 삽입 된다.
	//클러스터의 중심 값이 후보 리스트에 다시 등록되고
	//후보 리스트에서 선출된 노드를 후보 리스트에서 뽑아낸다.
	Node* pClusterList = *ClusterList;

	SLL_AppendNode(ClusterList, candidateNode);
	SLL_RemoveNode(CandidateList, candidateNode);
	candidateNode->NextNode = NULL;
	SLL_AppendNode(CandidateList, pClusterList);
	SLL_RemoveNode(ClusterList, pClusterList);
	pClusterList->NextNode = NULL;

}
Example #2
0
void Kmeans_TransferNode(Node** List, Node** List2, Node* TransferNode){
	//Node* pList1 = *List;
	//Node* pList2 = *List2;

	SLL_RemoveNode(List, TransferNode);
	TransferNode->NextNode = NULL;
	SLL_AppendNode(List2, TransferNode);
}
Example #3
0
void Kmeans_SetRandom(Node** Sample, Node* Cluster[]){
	int setnum[3] = {28, 80, 4};
	Node* Current = *Sample;
	Node* getCentroid[MAX_CLUSTER];
	int Count = SLL_GetNodeCount(Current);
	
	for(int i = 0 ; i < MAX_CLUSTER ; i++){
		getCentroid[i] = SLL_GetNodeAt(Current, setnum[i]);
		SLL_RemoveNode(Sample, getCentroid[i]);
		getCentroid[i]->NextNode = NULL;
		Cluster[i] = getCentroid[i];
	}
}
Example #4
0
int main(void) {

	int i = 0;
	int Count = 0;
	Node* List = NULL;
	Node* Current = NULL;
	Node* NewNode = NULL;

	for (i = 0; i<5; i++) {
		NewNode = SLL_CreateNode(i);
		SLL_AppendNode(&List, NewNode);
	}

	NewNode = SLL_CreateNode(-1);
	SLL_InsertNewHead(&List, NewNode);
	NewNode = SLL_CreateNode(-2);
	SLL_InsertNewHead(&List, NewNode);

	Count = SLL_GetNodeCount(List);
	for (i = 0; i < Count; i++) {
		Current = SLL_GetNodeAt(List,i);
		printf("List[%d] : %d\n", i,Current->Data);
	}

	printf("\nInserting 3000 after [2]...\n\n");

	Current = SLL_GetNodeAt(List,2);
	NewNode = SLL_CreateNode(3000);

	SLL_InsertAfter(Current,NewNode);

	Count = SLL_GetNodeCount(List);
	for (i = 0 ; i < Count ; i++) {
		Current = SLL_GetNodeAt(List,i);
		printf("List[%d] : %d\n", i,Current->Data);
	}

	printf("\nDestorying List...\n");

	for (i = 0; i < Count ; i++) {
		Current = SLL_GetNodeAt(List,0);

		if (Current != NULL) {
			SLL_RemoveNode(&List,Current);
			SLL_DestroyNode(Current);
		}
	}
}
Example #5
0
void Kmeans_GetRandom(Node** Sample, Node* Cluster[]){
	srand(time(NULL));
	int getRand ;
	
	Node* Current = *Sample;
	Node* getCentroid[MAX_CLUSTER];
	int Count = SLL_GetNodeCount(Current);
	
	for(int i = 0 ; i < MAX_CLUSTER ; i++){
		getRand = rand() % Count-- ;
		getCentroid[i] = SLL_GetNodeAt(Current, getRand);
		SLL_RemoveNode(Sample, getCentroid[i]);
		getCentroid[i]->NextNode = NULL;
		Cluster[i] = getCentroid[i];
	}
}