Consider the following code snippet to find the smallest element in a linked list:
struct Node
{
int val;
struct Node* next;
}*head;
int get_min()
{
struct Node* temp = head->next;
int min_num = temp->val;
while(temp != 0)
{
if(_________)
min_num = temp->val;
temp = temp->next;
}
return min_num;
}
Which of the following lines should be inserted to complete the above code?
struct Node
{
int val;
struct Node* next;
}*head;
int get_min()
{
struct Node* temp = head->next;
int min_num = temp->val;
while(temp != 0)
{
if(_________)
min_num = temp->val;
temp = temp->next;
}
return min_num;
}
A. temp > min_num
B. val > min_min
C. temp->val < min_num
D. temp->val > min_num
Answer: Option C
Join The Discussion