Refactor benchmark to use randomized vectors instead of sets
- Replaced std::set with std::vector for sequence handling. - Added randomization of sequences to avoid ordered input bias. - Removed unused balance function and related code in bst.cpp and bst.h. - Fixed bugs in list insertion and search logic. - Updated plot.py to allow custom y-axis labels and enable log scale for build plots.
This commit is contained in:
+2
-28
@@ -24,33 +24,6 @@ Tree *search(Tree *root, int value) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void traverseInOrder(Tree *root, std::vector<int> *vec) {
|
||||
if (root != nullptr) {
|
||||
traverseInOrder(root->left, vec);
|
||||
vec->push_back(root->info);
|
||||
traverseInOrder(root->right, vec);
|
||||
}
|
||||
}
|
||||
|
||||
Tree *rebuild(std::vector<int> *vec, int start, int end) {
|
||||
if (start > end)
|
||||
return nullptr;
|
||||
|
||||
int mid = (start + end) / 2;
|
||||
Tree *node = new Tree();
|
||||
node->info = vec->at(mid);
|
||||
node->left = rebuild(vec, start, mid - 1);
|
||||
node->right = rebuild(vec, mid + 1, end);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
Tree *balance(Tree *root) {
|
||||
std::vector<int> vec;
|
||||
traverseInOrder(root, &vec);
|
||||
return rebuild(&vec, 0, vec.size() - 1);
|
||||
}
|
||||
|
||||
void deleteTree(Tree *root) {
|
||||
if (root != nullptr) {
|
||||
deleteTree(root->left);
|
||||
@@ -60,7 +33,8 @@ void deleteTree(Tree *root) {
|
||||
}
|
||||
|
||||
int getHeight(Tree *root, int height) {
|
||||
if (root == nullptr) return height;
|
||||
if (root == nullptr)
|
||||
return height;
|
||||
height += 1;
|
||||
int leftHeight = getHeight(root->left, height);
|
||||
int rightHeight = getHeight(root->right, height);
|
||||
|
||||
Reference in New Issue
Block a user