Question
A linked list is formed from the objects of the class Node. The class structure of the Node is given below:
class Node
{
int n;
Node link;
}
Write an Algorithm OR a Method to search for a number from an existing linked list. The method declaration is as follows:
void FindNode( Node str, int b )
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
void FindNode(Node str, int b)
{
Node temp=str;
while(temp!=null)
{
if (temp.n == b)
{
System.out.prinln(b+" is found ");
break;
}
temp=temp.link;
}
}