2026-rff_mp/stepushovgs/data-structures/sorce/main_tree.c
GordStep 0e7a03e784 Обновление
- Изменение структуры лабораторной работы
- Завершение библитеки для Бинарного дерева поиска
2026-05-07 14:28:06 +03:00

87 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
#include "bin_search_tree/bst.h"
#define COUNT_NUMBERS 64
int isInArr(int arr[], int len, int target)
{
for (int i = 0; i < len; i++)
{
if (arr[i] == target) return 1;
}
return 0;
}
char get_dozen(int number)
{
return (char)'0' + number % 10;
}
char get_units(int number)
{
return (char)'0' + number / 10;
}
int main()
{
printf("hello world!\n");
//bst_node* head = create_bst_node("name", "phone");
bst_node* head = NULL;
int arr[COUNT_NUMBERS] = {0};
char name[NAME_LEN] = "name_xx";
char phone[PHONE_LEN] = "phone_xx";
int temp = 0;
for (int i = 0; i < COUNT_NUMBERS; i++)
{
do
{
temp = rand() % 100;
}
while (isInArr(arr, i - 1, temp));
arr[i] = temp;
name[5] = get_dozen(temp);
name[6] = get_units(temp);
phone[6] = get_dozen(temp);
phone[7] = get_units(temp);
head = bst_insert(head, name, phone);
printf("%d ", arr[i]);
}
printf("\n\ninorder traversal: \n");
bst_inorder_traversal(head);
printf("\n\npreorder traversal: \n");
bst_preorder_traversal(head);
char tar_name[NAME_LEN] = "name_44";
printf("\n\nУдаляем элемент с значением %s:\n", tar_name);
head = bst_delete(head, tar_name);
bst_inorder_traversal(head);
printf("\n\nВывод дерева:\n");
printTree(head, 0);
printf("\n\nОбход в ширину:\n");
treeLevelTraversal(head);
delete_bst(head);
return 0;
}