Bst Write C Functions Search Insert Delete Using Iterative Algorithm Q37148634

For BST, write C functions to search, insert and delete usingiterative algorithm.


Answer


#include<stdio.h>
#include<stdlib.h>
struct node
{
   struct node *left;
   int data;
   struct node *right;
}*start=NULL;
struct node *temp;
struct node * creat(struct node *root,int key)
{
   if(root==NULL)
   {
       root=(structnode*)malloc(sizeof(struct node));
       root->left=NULL;
       root->right=NULL;
       root->data=key;
   }
   if(key<root->data)
   {
      root->left=creat(root->left,key);  
   }
   else if(key>root->data)
   {
      root->right=creat(root->right,key);
   }
   return root;
}
struct node* min_value(struct node *root)
{
   struct node *current=root;
   while(current->left!=NULL)
   {
      current=min_value(current->left);  
   }
   return current;
}
struct node * dele(struct node *root,int key)
{
   temp=(struct node *)malloc(sizeof(structnode*));
   if(root==NULL)
   {
       return root;  
   }
   else if(key<root->data)
   {
      root->left=dele(root->left,key);  
   }
   else if(key>root->data)
   {
      root->right=dele(root->right,key);  
   }
   else
   {
       if(root->left==NULL)
       {
          temp=root->right;
  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.