Introduction To Data Structures - Study Mode
[#186] What is the functionality of the following code? Choose the most appropriate answer. public int function()
{
if(head == null)
return Integer.MIN_VALUE
int var
Node temp = head
Node cur
while(temp.getNext() != head)
{
cur = temp
temp = temp.getNext()
}
if(temp == head)
{
var = head.getItem()
head = null
return var
}
var = temp.getItem()
cur.setNext(head)
return var
}
Correct Answer
(B) Returns the data and deletes the node at the end of the list
[#187] What does the following function do for a given Linked List with first node as head? void fun1(struct node* head)
{
if(head == NULL)
return
fun1(head->next)
printf("%d ", head->data)
}
Correct Answer
(B) Prints all nodes of linked list in reverse order
[#188] After performing these set of operations, what does the final list look contain? InsertFront(10)
InsertFront(20)
InsertRear(30)
DeleteFront()
InsertRear(40)
InsertRear(10)
DeleteRear()
InsertRear(15)
display()
Correct Answer
(D) 10 30 40 15
[#189] 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
}
}
Correct Answer
(B) 2, 1, 4, 3, 6, 5, 7
[#190] Consider the following definition in c programming language. struct node
{
int data
struct node * next
}
typedef struct node NODE
NODE *ptr
Which of the following c code is used to create new node?
Correct Answer
(A) ptr = (NODE*)malloc(sizeof(NODE))