in DS recategorized by
301 views
3 votes
3 votes

A doubly linked list is declared as:

struct Node {
    int Value;
    struct Node *prev;
    struct Node *next;
};

Which of the following segment of code deletes the node pointed to by $\text{X}$ from the doubly linked list, if it is assumed that $\text{X}$ points to neither the first nor the last node of the list?

  1. $\text{X} \rightarrow$ prev $\rightarrow $ next $= \text{X} \rightarrow$ next $; \text{X} \rightarrow$ next $\rightarrow$ prev $= \text{X} \rightarrow$ prev; free(X);
  2. $\text{X} \rightarrow$ prev.next $ = \text{X} \rightarrow$ next $; X.$ next $\rightarrow$ prev $ = \text{X} \rightarrow$ prev; free(X);
  3. $\text{X} \rightarrow.$ prev $\rightarrow$ next $= \text{X}.$prev $; \text{X} \rightarrow$ next.prev $= \text{X}.$prev; free(X);
  4. $\text{X} \rightarrow$ prev $\rightarrow$ next $= \text{X} \rightarrow$ prev $; \text{X} \rightarrow$ next $\rightarrow$ prev $= \text{X} \rightarrow$ next; free(X);
in DS recategorized by
301 views

2 Answers

3 votes
3 votes

Answer is option A and we will see why other options are not correct

 

2 votes
2 votes

Answer to the question is Option A

Answer:

Related questions