-->

Thursday, March 20, 2014

C function to implement Linear Search in linked list for Data Structure

C function to implement Linear Search in linked list for Data Structure

C function to implement Linear Search in linked list:

   struct NODE
    {
       int INFO;
      struct NODE *LINK;
     };
     void search_11( struct NODE *ptr, int IN)
     {
      while(ptr !=NULL && ptr-->INFO !=IN)
        ptr =ptr-->LINK;
       if (ptr-->INFO == IN)
         printf(“Search successful”);
       else
          printf(“Search unsuccessful”);
       }

Other form of C function:

   struct NODE
    {
       int INFO;
      struct NODE *LINK;
     };
    int search_11 (struct NODE *ptr, int IN)
    {
      while(ptr !=NULL)
       {
        if(ptr-->INFO == IN)
         return 1;
        ptr = ptr->LINK;
        }
      return 0;
     }

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved