Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Aptitude | GATE CS 1998 | Question 75

  • Difficulty Level : Medium
  • Last Updated : 20 Mar, 2020

Let be a pointer as shown in the figure in a single linked list.
singlelinkedlist
What do the following assignment statements achieve ?

q: = p → next
p → next:= q → next 
q → next:=(q → next) → next 
(p → next) → next:= q


Answer:

Explanation: Initially p points to i and q points to i+1.

  1. p ->next:= q ->next : i next points to i+2
  2. q ->next:=(q ->next) ? next : i+1 next points to i+3
  3. (p ->next) ->next:= q : i+2 next points to i+1

Deducing finally i->i+2->i+1->i+3.

So, it swaps the two nodes next to p in the linked list.


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!