The following C function takes a simply-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank. Choose the correct alternative to replace the blank line.

`typedef` `struct` `node ` `{ ` ` ` `int` `value; ` ` ` `struct` `node *next; ` `}Node; ` ` ` `Node *move_to_front(Node *head) ` `{ ` ` ` `Node *p, *q; ` ` ` `if` `((head == NULL: || (head->next == NULL)) ` ` ` `return` `head; ` ` ` `q = NULL; p = head; ` ` ` `while` `(p-> next !=NULL) ` ` ` `{ ` ` ` `q = p; ` ` ` `p = p->next; ` ` ` `} ` ` ` `_______________________________ ` ` ` `return` `head; ` `} ` |

**(A)** q = NULL; p->next = head; head = p;

**(B)** q->next = NULL; head = p; p->next = head;

**(C)** head = p; p->next = q; q->next = NULL;

**(D)** q->next = NULL; p->next = head; head = p;

**Answer:** **(D)** **Explanation:** See question 1 of https://www.geeksforgeeks.org/data-structures-and-algorithms-set-24/

Quiz of this Question

## Recommended Posts:

- Data Structures | Balanced Binary Search Trees | Question 13
- Data Structures | Linked List | Question 16
- Data Structures | Linked List | Question 15
- Data Structures | Linked List | Question 10
- Data Structures | Linked List | Question 9
- Data Structures | Linked List | Question 8
- Data Structures | Stack | Question 5
- Data Structures | Hash | Question 1
- Data Structures | Linked List | Question 6
- Data Structures | Binary Search Trees | Question 1
- Data Structures | Linked List | Question 3
- Data Structures | Stack | Question 1
- Johnson’s algorithm for All-pairs shortest paths | Implementation
- FIFO (First-In-First-Out) approach in Programming
- FIFO vs LIFO approach in Programming