First of all, the very first line is wrong; you shouldn't put semicolon right before the body of the function. This will generate an error.
Secondly, maybe you will try to explain us step after step what you're doing(at higher level)? e.g. "First, I'm creating a node pointer to track elements I'm inspecting. Then, I start inspecting elements, by ...." etc.
Generally algorithm for sequential search(if it is what I think it is) works like this:
1 2 3 4 5 6
|
x = first element
while x != end of list
if x = wanted element
return x|index|whatever;
x = next element
return null;
|
If you allow circullar lists, you can do following:
1 2 3 4 5 6 7 8 9
|
x = y = first element
y = next element
while x != end of list and x != y
if x = wanted element
return x|index|whatever;
x = next element
y = next element
y = next element // Increment y twice
return null
|
Basically, the first option is trivial, the second one uses so called "fast" and "slow" pointers. If the list isn't circullar, y will reach the end quicker than x, and then it will be just next element of null(and next element of null is null. I also call it "end of list".).
If list is circullar, then x and y will meet, indicating that list is circullar, terminating search.