package tests;

import org.testng.annotations.Test;

class Node

{

int value;

Node next;

Node(int x)

{

value=x;

}

public void deleteNode(Node root,int n)

{

Node temp=root;

while(temp!=null)

{

System.out.println(temp.value);

if((temp.next!=null)&&(temp.next.value==n))

{

temp.next=temp.next.next;

}

temp=temp.next;

}

}

}

public class DeleteNodeTest {

@Test

public void testDeleteNode() {

Node one=new Node(1);

Node two=new Node(2);

Node three=new Node(3);

Node four=new Node(4);

Node five=new Node(5);

Node temp;

temp=one;

one.next=two;

two.next=three;

three.next=four;

four.next=five;

temp.deleteNode(one, 3);

}

}

### Like this:

Like Loading...

*Related*

## About qainterviews

Software Geek,QA Expert,Blogger