First decide when the method will stop i.e. what is the halting condition as given your question above again the method will start moving and will return to 2 and this process will continue ever. The only halting condition specified above is the occurrence of zero in the zero otherwise this program will never halt.
If coming to the head node can also result in halting of the program then the code can be completed in this way:
findHead(head,originalHead,calledCount){
if(originalHead==null)
{
return false;
}
else if (head==originalHead && calledCount>1)
/*If while roaming gets to the head then returns true but except the first time where the head will always be equal to original head */
{
return true;
}
else {
p=head;
if(p.data>0)
{
steps=p.data;
while(steps>0)
{
p=p->next;
steps--;
}
findHead(p,originalHead,calledCount);
}
else if(p.data<0)
{
steps=p.data;
while(steps<0)
{
p=p->prev;
steps++;
}
findHead(p,originalHead,calledCount);
}
else // If obtained 0 in the list
{
if (p==originalHead)
{
return true;
}
else
{
return false;
}
}
}
calledCount++;
}