The GATE Grind

GATE 2008 CS – Question 62

Programming and Data Structures · Linked Lists · 2 marks · Multiple choice

The list contains1, 2, 3, 4, 5, 6, 7. What is its content after this function?

struct node { int value; struct node *next; };
void rearrange(struct node *list) {
 struct node *p,*q; int temp;
 if (!list || !list->next) return;
 p=list; q=list->next;
 while(q) {
  temp=p->value; p->value=q->value; q->value=temp;
  p=q->next; q=p ? p->next : 0;
 }
}
  1. 1, 2, 3, 4, 5, 6, 7
  2. 2, 1, 4, 3, 6, 5, 7
  3. 1, 3, 2, 5, 4, 7, 6
  4. 2, 3, 4, 5, 6, 7, 1

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 2, 1, 4, 3, 6, 5, 7

Explanation

We are sorry we couldn't write detailed soluition for this, we are working on it!, please consider asking your own AI, its just 2-3 clicks with very minimum effort

More Linked Lists questions

All Linked Lists questions →