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

March 20, 2014 0 Comments

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;
     }

Jackrin Reacher

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments: