icse-promo

Question

A linked list is formed from the objects of the class ,
class Node
{
    int number;
    Node nextNode;
}
Write a method OR an algorithm to add a node at the end of existing the linked list .The method declaration is specified below:
void addnode(Node start,int num);

Share code with your friends

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

Code

				
					void addnode(Node start,int num)
{		
    Node temp=new Node(start);
    
    while(temp.nextNode!=null)
    {	
        temp=temp.nextNode;
    }
    Node C=new Node();
    C.number=num;
    C.nextNode=null;
    temp.nextNode=C;
}

				
			

Coding Store

Leave a Reply

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