Hello friends!!!!!
Binary Search Tree
// Implementation of Binary Tree using Linked List
#include <stdio.h>
#include<stdlib.h>
typedef struct Node{
int data;
struct Node *left;
struct Node *right;
}Node;
Node * Create_Node(int value){
Node *new_node;
new_node = (Node *)malloc(sizeof(Node));
if(new_node == NULL){
return NULL;
}
else{
new_node -> data = value;
new_node -> left = NULL;
new_node -> right = NULL;
return new_node;
}
}
Node *create_root(int value){
Node *root = Create_Node(value);
if(root == NULL){
printf("Root Value inserted\n");
}
return root;
}
Node Insert(Node root, int value) {
if (root == NULL) {
return Create_Node(value);
}
if (value < root -> data) {
root -> left = Insert(root -> left, value);
printf("Value %d inserted at left.\n", value);
}
else if (value > root -> data) {
root -> right = Insert(root ->right, value);
printf("Value %d inserted to the right.\n", value);
}
else {
printf("Sorry the value %d is not inserted.\n", value);
}
return root;
}
void display(Node * root){
if(root != NULL){
printf("%d ", root -> data);
display(root->left);
display(root->right);
}
}
int main() {
Node *root = Create_Node(20);
Insert(root, 15);
Insert(root , 40);
Insert(root,90);
Insert(root, 10);
printf("\n Pre - order : \n");
display(root);
return 0;
}