Algorithm to search element in the Linked list

Search_LL(List, element, Start)

Here, List is a Linked list containing n elements, in which we have to search element. Start is a pointer which is containing the address of starting Node. SUCCESS=1 is a constant which will be returned on successful search and FAILURE=0 is a constant which will be returned on unsuccessful search. Ptr is a intermediate pointer which is used to traverse the list.

Step 1: [check, if list is empty]
            If Start = null then 
                   return FAILURE;
Step 2: Ptr = Start
Step 3: While Ptr < > null repeat step 4
Step 4: i) If Ptr -> Data = Element then 
                    return SUCCESS;
           ii) Ptr = Ptr->Next
Step 5: return FAILURE;
Step 6: End



Click here for Explanation

No comments:

Post a Comment