#include#include #include #define DATANUM 1000 struct BinarySearchTree{ int data; struct BinarySearchTree *left; struct BinarySearchTree *right; }; struct BinarySearchTree bst[DATANUM]; int makeBinarySearchTree(){ struct BinarySearchTree *current; int i, depth, maxDepth; srand((unsigned int)time(NULL)); bst[0].data = rand(); bst[0].left = NULL; bst[0].right = NULL; maxDepth = 0; for (i = 1; i < DATANUM; i++){ bst[i].data = rand(); bst[i].left = NULL; bst[i].right = NULL; current = &bst[0]; depth = 1; while (-1){ if(bst[i].data < current->data){ if (current->left == NULL){ current->left = &bst[i]; break; } else { current = current->left; depth++; } } else { if (current->right = NULL){ current->right = &bst[i]; break; } else { current = current->right; depth++; } } } if (depth > maxDepth) maxDepth = depth; } return maxDepth; } int main(){ int i, sum; sum = 0; for (i = 1; i <= 10000; i++){ sum += makeBinarySearchTree(); } printf("DATANUM = %d\n", DATANUM); printf("max depth average is = %lf\n", sum / 10000.0); return 0; }

