Linked List 2018

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 )

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. Display number not found
Step 4. check for number , if found display, exit
Step 5. Move pointer to the next node
Step 6. End algorithm

METHOD: 
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; 
	} 
} 
This entry was posted in Linked list. Bookmark the permalink.

Leave a Reply

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