struct Node* root = newNode(6);

#include<iostream>

using namespace std;
struct node {
int data;
struct node *left;
struct node *right;
};
struct node *createNode(int val) {
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->data = val;
temp->left = temp->right = NULL;
return temp;
}
void inorder(struct node *root) {
if (root != NULL) {
inorder(root->left);
cout<data<<” “; inorder(root->right);
}
}
struct node* insertNode(struct node* node, int val) {
if (node == NULL) return createNode(val);
if (val < node->data)
node->left = insertNode(node->left, val);
else if (val > node->data)
node->right = insertNode(node->right, val);
return node;
}
int main() {
struct node *root = NULL;
root = insertNode(root, 6);
insertNode(root, 4);
insertNode(root, 8);
insertNode(root, 1);
insertNode(root,5);
cout<<“In-Order traversal of the Binary Search Tree is: “;
inorder(root);
return 0;

By RRR

Leave a Reply

Your email address will not be published.