Program No 15 Aim: Program Code:: Write A Program To Implement Binary Search Tree With All Its Operations
Program No 15 Aim: Program Code:: Write A Program To Implement Binary Search Tree With All Its Operations
Program No 15
Aim: Write a Program to implement Binary Search Tree
with all its operations
Program Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
// Node structure
struct Node {
int info;
};
// Global pointers
// Function prototypes
printf("\nNode is available");
do {
break;
printf("\n1. Insert Node in BST");
inorder(root);
switch (choice) { break;
case 1:
break;
default:
return ptr;
printf("\nDo you want to continue
(y/n): "); if (value < ptr->info)
struct Node *insert(struct Node *node, // Function to delete a node from BST
int value) {
struct Node *delet(struct Node *ptr, int
if (node == NULL) { value) {
node->left = insert(node->left,
value);
if (value < ptr->info) {
} else {
ptr->left = delet(ptr->left, value);
node->right = insert(node->right,
value); return ptr;
} return ptr;
free(ptr);
// In-order traversal
return temp;
void inorder(struct Node *ptr) {
} else if (ptr->right == NULL) {
if (ptr != NULL) {
struct Node *temp = ptr->left;
inorder(ptr->left);
free(ptr);
printf("|%d|", ptr->info);
return temp;
inorder(ptr->right);
} else {
}
struct Node *min =
getMinimumNode(ptr->right); }
ptr->info = min->info;
temp->info = value;
// Function to get node with minimum
value (in-order successor) temp->left = NULL;
OUTPUT:
1. Insert Node in BST
2. Search a Node in BST
3. Delete a Node in BST
4. InOrder Traversing
Enter your choice: 1
|10||25|