#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;
}
