A struct Node(shown below) is used to implement a linked list.
struct Node {
int data;
struct Node* next;
}
The function a_function (shown below), takes the head (i.e. the first element of the list), as argument, and reorders the list.The swap function inside the function, swaps the 2 elements of the list, which are passed to it as arguments
void a_function (Node* head) {
Node* a_ptr = head;
bool val = true;
while (a_ptr->next != NULL) {
if (val) {
if (a_ptr->data > a_ptr->next->data)
swap(a_ptr->data, a_ptr->next->data);
}
else {
if (a_ptr->data < a_ptr->next->data) {
swap(a_ptr->data, a_ptr->next->data);
}
a_ptr = a_ptr->next;
val = !val;
}
}
}
Choose all options, that are correct about the above function a_function
a>The function,a_function, sorts the linked lest in ascending order.,
b>The function, a_function, rearranges the list in zigzag fashion (i.e. a,b,c,d,e,f... be the data in the list after the list is rearranged, then the list is of the form a < b > c < d > e < f...)
c>Given a list 4, 3, 7, 8, 6, 2, 1. The function, a_function, rearranges it to 3, 7, 4, 8, 2, 6, 1.
d>Given a list 11, 15, 20, 16, 21, 23, 17. The function, a_function, rearranges it to 11, 15, 16, 17, 20, 21, 23.