Consider the following linked list:

\"\"

S is the header pointer and P is an empty pointer. Perform given operations in sequence in this linked list:

(i) P = S → next → next → next 
(ii) P → next → next → next → next = S → next → next → next → next
(iii) S → next → next → next = P → next → next
(iv) X = S → next → next → next → next → next → next → next → data 

What will be the value of X?
(A) 5
(B) 6
(C) 7
(D) Segmentation Error


Answer: (C)

Explanation: Final linked list will be as given below after performing given operation in sequence:

(i) P = S → next → next → next 
P = 1000 → 2000 → 3000 → 4000
 
(ii) P → next → next → next → next = S → next → next → next → next
P → 5000 → 6000 → 7000 → null = S → 2000 → 3000 → 4000 → 5000

(iii) S → next → next → next = P → next → next 
S → 2000 → 3000 → 4000 = P → 5000 → 6000 

\"\"

Therefore, value of X will be:

X = S → next → next → next → next → next → next → next → data 

X = 1000 → 2000 → 3000 → 6000 → 7000 → 5000 → 6000 → 7000 → 7
X = 7

So, option (C) is correct.

Quiz of this Question


  • Last Updated : 14 Nov, 2018

Share your thoughts in the comments