icse-promo

Question

A linked list is formed from the objects of the class ,

class Node
{
String name;
Node next;
}

Write a method OR an algorithm to search for a given name in the linked list .The method declaration is specified below:

boolean searchName(Node start,String v);

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					boolean searchName(Node start,String v)
{
    Node temp=new Node(start);
    while(temp!=null)
    {
        if(temp.name.equals(v)==true)
        {
            return true;
        }
        temp=temp.next;
    }
    return false;
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *