Search

Thursday, March 20, 2014
0 comments

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

7:06 AMThursday, March 20, 2014

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

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top