generated from freudenreichan/info2Praktikum-DobleSpiel
bintree verbesserung numbers neu
This commit is contained in:
parent
94e58e45bd
commit
2ae4ca5cbe
19
bintree.c
19
bintree.c
@ -35,11 +35,11 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
|||||||
|
|
||||||
if (cmp == 0){
|
if (cmp == 0){
|
||||||
|
|
||||||
|
/*
|
||||||
if (isDuplicate == NULL){
|
if (isDuplicate == NULL){
|
||||||
root->right = addToTree(root->right, data, dataSize, compareFct, NULL);
|
root->right = addToTree(root->right, data, dataSize, compareFct, NULL);
|
||||||
return root;
|
return root;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
*isDuplicate = 1;
|
*isDuplicate = 1;
|
||||||
return root;
|
return root;
|
||||||
@ -60,7 +60,13 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
|||||||
// push the top node and push all its left nodes.
|
// push the top node and push all its left nodes.
|
||||||
void *nextTreeData(TreeNode *root)
|
void *nextTreeData(TreeNode *root)
|
||||||
{
|
{
|
||||||
|
if (root != NULL){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Releases all memory resources (including data copies).
|
// Releases all memory resources (including data copies).
|
||||||
@ -90,3 +96,12 @@ unsigned int treeSize(const TreeNode *root)
|
|||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int compareFct(const void *a, const void *b){
|
||||||
|
|
||||||
|
if(*a>*b)return -1;
|
||||||
|
if(*b>*a)return 1;
|
||||||
|
if(*a==*b)return 0;
|
||||||
|
|
||||||
|
}
|
||||||
36
numbers.c
36
numbers.c
@ -19,30 +19,34 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
unsigned int* numbers =malloc(sizeof(unsigned int) * len);
|
unsigned int* numbers =malloc(sizeof(unsigned int) * len);
|
||||||
unsigned int numberTemp;
|
unsigned int numberTemp;
|
||||||
bool check = false;
|
unsigned int* numbTempPtr = &numberTemp;
|
||||||
|
int generated = 0;
|
||||||
|
int isDuplicate = 0;
|
||||||
|
TreeNode* root = NULL;
|
||||||
|
|
||||||
for(int i = 0; i < len; i++){
|
|
||||||
|
|
||||||
while(check == false){
|
while(genreated<len){
|
||||||
numberTemp = (rand() % 2*len)+1;
|
|
||||||
|
|
||||||
for(int j = 0; j < i; j++){
|
numberTemp = (rand() % 2*len)+1;
|
||||||
if(numberTemp == numbers[j]){
|
root = addToTree( root, numbTempPtr, sizeof(unsigned int), compareFct, isDuplicate );
|
||||||
check = false;
|
|
||||||
|
|
||||||
break;
|
if(!isDuplicate){
|
||||||
}
|
|
||||||
|
|
||||||
if(j + 1 == i){
|
numbers[genreated] = numberTemp;
|
||||||
check = true;
|
genreated++;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
numbers[i] = numberTemp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DuplicateId;
|
||||||
|
int DuplicatePlace;
|
||||||
|
do{
|
||||||
|
DuplicateId = rand()%len;
|
||||||
|
DuplicatePlace = rand() % len;
|
||||||
|
}while(DuplicateId != DuplicatePlace);
|
||||||
|
|
||||||
|
numbers[DuplicatePlace] = numbers[DuplicteId];
|
||||||
|
|
||||||
return numbers;
|
return numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user