Я борюсь с проверкой дерева AVL. Моя программа работает как задумано, однако я не могу понять, как привести числа в правильную форму. Мой тестовый код:
void test_left_rotation_with_parent() {
//Arrange
struct Node* root = NULL;
int insert_nodes[] = { 5,10,15 };
int test_output[6]; // this is where my numbers should be
int correct_output[] = { 10,2,5,1,15,1, };
char* passed = PASSED;
//Act
for (int i = 0; i < 3; i++) {
root = add(root, insert_nodes[i]);
}
preOrder(root); // this is my function, see below
int index = print_pre_order(root, test_output, 0); // I cannot figure out what this is for
//Assert
for (int i = 0; i < 6; i++) {
if (correct_output[i] != test_output[i]) {
passed = FAILED;
break;
}
}
printf("%s: %s\n", __func__, passed);
У меня есть функция с именем preOrder, которая выглядит следующим образом:
void preOrder(struct Node *root)
{
if (root != NULL)
{
printf("%d,", root->key);
printf("%d,", root->height);
preOrder(root->link[0]); // left
preOrder(root->link[1]); // right
}
}
Вывод:
10,2,5,1,15,1,test_left_rotation_with_parent: FAILED
Мне нужно поставить эти числа в этом порядке в массиве, так что ключ идет на первое место, высота на второе для каждого узла.