icse-promo

Question

A linked list is formed from the objects of the class ,
class Node
{
int info;
Node link;
}
Write a method OR an algorithm deleting a node in the linked list .The method declaration is specified below:
void deleteNode(Node start);

Share code with your friends

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

Code

				
					void deleteNode(Node start)
{
    Scanner sc=new Scanner(System.in);
    int n=0;
    System.out.println("ENTER INFO FOR THE NODE TO BE DELETED");
    n=sc.nextInt();
    Node a=new Node(start);
    if(start.info==n)
    {
        a=start;
        start=start.link;
        a.link=null;
    }
    else
    {
        a=a.link;
        Node b=new Node(start);
        while(a.info!=null)
        {
            if(a.info==n)
            {
                b.link=a.link;
                a.link=null;
                break;
            }
        }
    }
    
}


				
			

Coding Store

Leave a Reply

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