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);
		}
	}
}
Exemple #2
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];
	}
}
Exemple #3
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];
	}
}