adplus-dvertising
frame-decoration

Question

The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list.
The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?
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;
    }
}

a.

1, 2, 3, 4, 5, 6, 7

b.

2, 1, 4, 3, 6, 5, 7

c.

1, 3, 2, 5, 4, 7, 6

d.

2, 3, 4, 5, 6, 7, 1

Answer: (b).2, 1, 4, 3, 6, 5, 7

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the...

Similar Questions

Discover Related MCQs

Q. Which of the following is not a disadvantage to the usage of array?

Q. What is the time complexity of inserting at the end in dynamic arrays?

Q. What is the time complexity to count the number of elements in the linked list?

Q. What is the space complexity for deleting a linked list?

Q. Which of these is an application of linked lists?

Q. What differentiates a circular linked list from a normal linked list?

Q. What is the time complexity of searching for an element in a circular linked list?

Q. Which of the following application makes use of a circular linked list?

Q. Which of the following is false about a circular linked list?

Q. Consider a small circular linked list. How to detect the presence of cycles in this list effectively?

Q. What is a skip list?

Q. Skip lists are similar to which of the following datastructure?

Q. What is the time complexity improvement of skip lists from linked lists in insertion and deletion?

Q. To which datastructure are skip lists similar to in terms of time complexities in worst and best cases?

Q. The nodes in a skip list may have many forward references. their number is determined

Q. Are the below statements true about skiplists?
In a sorted set of elements skip lists can implement the below operations

i.given a element find closest element to the given value in the sorted set in O(logn)

ii.find the number of elements in the set whose values fall a given range in O(logn)

Q. How to maintain multi-level skip list properties when insertions and deletions are done?

Q. Is a skip list like balanced tree?

Q. What is indexed skip list?

Q. What is xor linked list ?