...
Question 10330 – Queues-and-Stacks
November 6, 2023
Question 1999 – KVS 22-12-2018 Part-B
November 6, 2023
Question 10330 – Queues-and-Stacks
November 6, 2023
Question 1999 – KVS 22-12-2018 Part-B
November 6, 2023

Question 1084 – Nielit Scientist-B CS 22-07-2017

What does the following functions 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

Question 1 Explanation: 
Given pointer to the head node of a linked list, the task is to reverse the linked list. We need to reverse the list by changing links between nodes.
Input : Head of following linked list
1->2->3->4->NULL
Output : Linked list should be changed to,
4->3->2->1->NULL
Algorithm:
1. Initialize three pointers prev as NULL, curr as head and next as NULL.
2. Iterate through the linked list. In loop, do following.
// Before changing next of current,
// store next node
next = curr->next
// Now change next of current
// This is where actual reversing happens
curr->next = prev
// Move prev and curr one step forward
prev = curr
curr = next
A
Prints all nodes of linked lists
B
Prints all nodes of linked list in reverse order
C
Prints alternate nodes of Linked List
D
Prints alternate nodes in reverse order
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!