0% found this document useful (0 votes)
7 views4 pages

Dsu Pr26 Main

Uploaded by

vedantwalanj18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Dsu Pr26 Main

Uploaded by

vedantwalanj18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Q.

Program to Implement BST (Binary search Tree) traverse in In-Order

/*_________________Name: Vedant Walanj_______________*/

/*_________________Roll no:960______________________*/

/*_________________Branch: SYCO____________________*/

/*_________________Subject: DSU__________________*/

/*_________________Practical no:26__________________*/

/*__program to Implement BST (Binary search Tree) traverse in In-Order __*/

/*_________________Date:15/10/24____________________*/

#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node* left;
struct Node* right;
};
struct Node* createNode(int data)
{
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
}
struct Node* insert(struct Node* node, int data)
{
if (node == NULL) return createNode(data);
if (data < node->data)
node->left = insert(node->left, data);
else if (data > node->data)
node->right = insert(node->right, data);
return node;
}
void inOrder(struct Node* root)
{
if (root != NULL)
{
inOrder(root->left);
printf("%d ", root->data);
inOrder(root->right);
}
}
int main()
{
struct Node* root = NULL;
int choice, value;

while (1) {
printf("\n--- Binary Search Tree Operations ---\n");
printf("1. Insert\n");
printf("2. In-Order Traversal\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice)
{
case 1:
printf("Enter the value to insert: ");
scanf("%d", &value);
root = insert(root, value);
printf("Inserted %d\n", value);
break;
case 2:
printf("In-Order Traversal: ");
inOrder(root);
printf("\n");
break;
case 3:
printf("Exiting...\n");
return 0;
default:
printf("Invalid choice! Please try again.\n");
}
}
return 0;
}
/*______________End of theProgram___________________________*/
/*____________Output of the Program_________________________*/

You might also like