#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct node
{
    char info[20];
    struct node *left,*right;
}
tree_type;
void search(tree_type*,char []);
int display(tree_type*);
int main()
{
      tree_type *root=NULL;
      FILE *fp;
      int i=0,ch;
      char fname[20],str[20],c;
      printf("Enter the filename : ");
      scanf("%s",fname);
      fp=fopen(fname,"r");
      while((c=getc(fp))!=EOF)
      {
        if(c==' ')
            {
                str[i]='\0';
                insert(&root,str);
                i=0;
            }
        else
        {
            str[i]=c;
            i++;
        }
    }
    fclose(fp);
do{
               printf("\n1.Display and Count\n2.search\n3.Exit\nChoice : ");
               scanf("%d",&ch);
               switch(ch)
               {
                    case 1: c=display(root);
                    printf("\n\nNumber of nodes = %d",c);
                    break;
                    case 2: printf("Enter the field to be searched: ");
                    scanf("%s",str);
                    search(root,str);
                    break;
                    case 3: break;
                    default:
                    printf("Enter the correct choice: ");
               }
          }while(ch!=3);
}
void insert(tree_type **rt,char str[20])
{
     tree_type *p;
     p=(tree_type*)malloc(sizeof(tree_type));
     if(p!=NULL)
     {
          strcpy(p->info,str);
          p->right=NULL;
          p->left=NULL;
          if(*rt==NULL)
               *rt=p;
          else
          {
                if(strcmp(str,((*rt)->info))<0)
                      insert(&((*rt)->left),str);
                else
                      insert(&((*rt)->right),str);
          }
     }
}
int display(tree_type *rt)

    static int c=0;
    if(rt==NULL)
    {
        return c;
    }
    else
    {
        display(rt->left);
        printf("- %s",rt->info);
        c++;
        display(rt->right);
    }
}
void search(tree_type *rt,char str[20])
{       if(rt==NULL)
      {
          printf("NOT FOUND");
          return;
      }
      if(strcmp(str,rt->info)==0)
      {
          printf("FOUND");
          return;
      }
      else
      {
           if(strcmp(str,rt->info)<0)
                 search(rt->left,str);
           else
                 search(rt->right,str);
      }
}
//output- //
/

Search

Project Categories

Recent Posts

Mail Management System
Posted on 2019-07-18
Online food ordering system
Posted on 2019-07-18
Library Management System
Posted on 2019-07-17
Health center system project
Posted on 2019-07-17
Gym Management System
Posted on 2019-07-17
furniture management system
Posted on 2019-07-17
Electronic shop management system
Posted on 2019-07-17
Automobile Workshop Management
Posted on 2019-07-17
Online Visa Processing System
Posted on 2019-07-17
Inventory management System
Posted on 2019-07-17
petrol-management system
Posted on 2019-07-17
Cloths management system
Posted on 2019-07-17
Society Management system
Posted on 2019-07-17
Mall management system
Posted on 2019-07-17
school management system
Posted on 2019-07-17
Sales Order Processing System
Posted on 2019-07-17
Retail sales management
Posted on 2019-07-17
Raw Materials Management
Posted on 2019-07-17
railway reservation system
Posted on 2019-07-17
purchase and sales management system
Posted on 2019-07-17
Placement Management System
Posted on 2019-07-17
Pet Shop Management System
Posted on 2019-07-17
petrol pump management system
Posted on 2019-07-17
Patient Information System
Posted on 2019-07-17
news agency system
Posted on 2019-07-17
Cinema Booking System
Posted on 2019-07-17
Medical Store System
Posted on 2019-07-17
leave management System
Posted on 2019-07-17
Laboratory Information Management System
Posted on 2019-07-17
content management system
Posted on 2019-07-17
Inventory management System
Posted on 2019-07-17
Institute Management System
Posted on 2019-07-17
Hotel management System
Posted on 2019-07-17
Gym Management System
Posted on 2019-07-17
Garage Management System
Posted on 2019-07-17
Furniture shop management system
Posted on 2019-07-17
Fisheries management  System
Posted on 2019-07-17
Fertilizer scheduling system
Posted on 2019-07-17
online eye care system
Posted on 2019-07-17
Dental Clinic Management System
Posted on 2019-07-17
Cyber Café Management
Posted on 2019-07-17
Milk Billing System
Posted on 2019-07-17
Colddrink management system
Posted on 2019-07-17
Cable management System
Posted on 2019-07-17
Beauty parlor management system
Posted on 2019-07-17
Facebook Clone
Posted on 2019-05-28
Dance Class Management System
Posted on 2019-05-24
Library Management System
Posted on 2019-05-24
Cab Management System
Posted on 2019-05-23
Blood Bank Management system
Posted on 2019-05-23
Beauty Parlour Management System
Posted on 2019-05-23
vissa proccesing system
Posted on 2019-05-23
Toll Plazza
Posted on 2019-05-23
BILLING APPLICATION
Posted on 2019-05-23
FLORICULTURE MANAGEMENT SYSTEM
Posted on 2019-05-23
Car On Rent
Posted on 2019-05-23
E-commers Shop
Posted on 2019-05-23

Sign In