Linked List 2016

A linked list is formed from the objects of the class Node. The class structure of the Node is given below:
class Node
{
String name;
Node next;
}
Write an Algorithm OR a Method to search for a given name in the linked list. The method of declaration is given below:
boolean searchName(Node start, String v)

ALGORITHM:
Step 1. Start
Step 2. Set temporary pointer to the first node
Step 3. Repeat steps 4 and 5 until the pointer reaches null
Step 4. Search for the node. If found display details, exit
Step 5. Move pointer to the next node
Step 6. End

METHOD: 
boolean searchName(Node start, String v) 
{ 
	Node temp=new Node(start); 
	while(temp.name.equals(v) = = false && temp.next!=null) 
		temp=temp.next; 
	if(temp.next!=null) 
		return true; 
	else 
		return false; 
}
This entry was posted in Linked list. Bookmark the permalink.

Leave a Reply

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