#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bintree.h"
#include "node.h"
int main()
{
// 1)
t_tree tree = createEmptyTree();
for (int cpt=5; cpt >=1; cpt--) {
insertBST(&tree, cpt);
displayTree(tree);
}
printf("is a BST ? %d \n", checkBST(tree));
// 2)
t_tree tree2 = createEmptyTree();
insertBST(&tree2, 8);
displayTree(tree2);
insertBST(&tree2, 6);
displayTree(tree2);
insertBST(&tree2, 13);
displayTree(tree2);
insertBST(&tree2, 3);
displayTree(tree2);
insertBST(&tree2, 7);
displayTree(tree2);
insertBST(&tree2, 10);
displayTree(tree2);
insertBST(&tree2, 14);
displayTree(tree2);
insertBST(&tree2, 1);
displayTree(tree2);
insertBST(&tree2, 4);
displayTree(tree2);
printf("is a BST ? %d \n", checkBST(tree2));
return 0;
}#ifndef UNTITLED_BINTREE_H
#define UNTITLED_BINTREE_H
#include "node.h"
typedef struct s_tree
{
p_node root;
} t_tree, *p_tree;
void insertBST(t_tree *, int);
// ajoutez ici le prototype de isBST() si vous voulez l'utiliser
// pour utiliser l'affichage d'arbres
#define LINE_SIZE 1024
#define MAX_NB_LINES 100
int _print_t(p_node, int , int , int, char s[MAX_NB_LINES][LINE_SIZE]);
void print_t(p_node);
void displayTree(t_tree);
// other prototypes for functions in libs
// DO NOT EDIT
int isNodeBST(p_node);
int checkBST(t_tree);
t_tree createEmptyTree();
t_tree createBSTfromArray(int *, int);
#endif//
// Created by flasque on 26/06/2022.
//
#include <stdlib.h>
#include <stdio.h>
#include "node.h"
p_node createNode(int val)
{
p_node nouv;
nouv = (p_node)malloc(sizeof(t_node));
nouv->value = val;
nouv->left = nouv->right = NULL;
return nouv;
}#include "bintree.h"
#include <stddef.h>
// definition de la fonction insertBST()
void insertBST(t_tree *tree, int value) {
p_node node = createNode(value);
if (tree->root == NULL) {
tree->root = node;
} else {
p_node current = tree->root;
while (current != NULL) {
if (value < current->value) {
if (current->a == NULL) {
current->a = node;
break;
} else {
current = current->a;
}
} else {
if (current->b == NULL) {
current->b = node;
break;
} else {
current = current->b;
}
}
}
}
}