A doubly linked list is declared as struct Node{                 int Value;                 struct Note*fwd;                 struct Node * Bwd; } Where Fwd and Bwd represent forward and backward link to the adjacent elements of the list. Which of the following segments of code deletes the node pointed to by X from the doubly liked list, if it is assumed that X points to neither the first nor the last node of the list?

A doubly linked list is declared as struct Node{                 int Value;                 struct Note*fwd;                 struct Node * Bwd; } Where Fwd and Bwd represent forward and backward link to the adjacent elements of the list. Which of the following segments of code deletes the node pointed to by X from the doubly liked list, if it is assumed that X points to neither the first nor the last node of the list? Correct Answer x → Bwd → Fwd = X → Fwd → Bwd = X → Bwd;

code:

struct Node{

                int Value;

                struct Note*fwd;

                struct Node * Bwd;

}

Explanation:

It is given that X points to neither the first nor the last node of the list, So we need to give code to delete the intermediate node of the doubly linked list.

Address

1000

2000

3000

Node

A

X

B

 

Delete X:

A → Fwd = X → Fwd

B → Bwd = X → Bwd

Also:

A → Fwd  = X → Bwd → Fwd

B → Bwd = X → Fwd → Bwd

Therefore:

x → Bwd → Fwd = X → Fwd → Bwd = X → Bwd;.

Will delete X:

Hence option 1 is correct

Related Questions