Introduction To Data Structures - Study Mode

[#176] The following C function takes a simply-linked list as an 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
}
Correct Answer

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

[#177] Assuming int is of 4bytes, what is the size of int arr[15]
?
Correct Answer

(D) 60

[#178] How do you initialize an array in C?
Correct Answer

(C) int arr[3] = {1,2,3}

[#179] How do you insert an element at the beginning of the list?
Correct Answer

(A) public void insertBegin(Node node) { node.setNext(head) head = node size++ }

[#180] What is the output of the following Java code? public class array
{
public static void main(String args[])
{
int []arr = {1,2,3,4,5}
System.out.println(arr[2])
System.out.println(arr[4])
}
}
Correct Answer

(A) 3 and 5