GATE 2008 CS – Question 62
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;
}
}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