Skip to content
Related Articles

Related Articles

Improve Article

GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 33

  • Last Updated : 26 Dec, 2019

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

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :