Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
public int seqSearch(T[] list, int length, T searchItem)
{
    int loc; 
    boolean found = false;
    for(loc = 0; loc < length; loc++)
    {
        if(list[loc].equals(searchItem))
        {
           found = true;
           break; 
        }
    }

    if(found)
        return loc;
    else
        return-1;
}
Posted
Updated 15-May-12 13:04pm
v3
Comments
TRK3 15-May-12 19:05pm    
Fixed formatting and code tags.

What's your question?
Sergey Alexandrovich Kryukov 15-May-12 20:00pm    
So, Java or C++? Tag it properly.
And where is the question?
--SA

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

You might also want to get together with the rest of your class - one of them is here: recursive sequential search[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900