Hello friends!!!!!

Implementation of Binary Tree using Linked List

// 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;

}

void Insert_Left(Node * parent,int value){

if(parent == NULL){

printf("Cannot insert the value as parent value not exist\n");

}

else if(parent -> left != NULL){

printf("Sorry Left Value already exists\n");

}

else{

parent -> left = Create_Node(value);

printf("Value Inserted at left successfully\n");

}

}

void Insert_Right(Node * parent,int value){

if(parent == NULL){

printf("Cannot insert the value as parent value not exist\n");

}

else if(parent -> right != NULL){

printf("Sorry Left Value already exists\n");

}

else{

parent -> right = Create_Node(value);

printf("Value Inserted at right successfully\n");

}

}

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_Left(root, 30);

Insert_Right(root , 40);

Insert_Left(root->left,90);

Insert_Right(root->left, 10);

printf("\n Pre - order : \n");

display(root);

return 0;

}