Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL



Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1..

Answer / Ganesh Pratap Singh

To reverse a linked list, you can create a recursive function that swaps the current node's next pointer with its previous node. Here is an example implementation in C++:n```nNode* reverseList(Node* head) {n if (head == NULL || head->next == NULL) return head;n Node* newHead = reverseList(head->next);n head->next->next = head;n head->next = NULL;n return newHead;n}n``

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is unary operator? List out the different operators involved in the unary operator.

1 Answers  


Explain selection sorting?

1 Answers  


what is data abstraction in C++?

1 Answers  


What is the difference between Class and Structure?

40 Answers   HP, IBM, Samsung, TCS,


Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

1 Answers  


What is the best c++ book?

1 Answers  


Define a nested class.

1 Answers  


Can we use clrscr in c++?

1 Answers  


How many types of comments are there in c++?

1 Answers  


What are structures and unions?

1 Answers  


What are containers in c++?

1 Answers  


Can class objects be passed as function arguments?

1 Answers   HCL,


Categories