icse-promo

Question

A linked list is formed from the objects of the class ,
class node
{
int p;
String n;
node next;
}
Write a method OR an algorithm to search for a name and display the contents of that node .The method declaration is specified below:
void search(node start,String b);

Share code with your friends

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

Code

				
					void search(node start,String b)
{		
    node temp=new node(start);
    int f=-1;
    while(temp!=null)
    {	
        if(temp.n.equals(b)==true)
        {
            f=1;
            break;
        }
        temp=temp.next;
        
        
    }
    
    if(f==1)
    { 
        System.out.println(temp.n+" found");
        System.out.prinlnt("Content:"+temp.p);

    } 
    else
    {
        System.out.println("Node not found");
    }
}

				
			

Coding Store

Leave a Reply

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