create an singly linked lists and reverse the lists by
interchanging the links and not the data?

Answer Posted / nash

If the Linked list is small enough i'd use a recursive function.

reverse(head, head, NULL);

void reverse(Node* headNode, Node* currNode, Node* prevNode)
{
if(headNode != NULL && currNode != NULL)
{
reverse(currNode.next, currNode);
}
else
{
headNode = currNode; // Reached the end of the list.
}

currNode.next = prevNode;
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is hashmap keyset ordered?

555


Explain the term tail recursion?

553


For the following COBOL code, draw the Binary tree? 01 STUDENT_REC. 02 NAME. 03 FIRST_NAME PIC X(10). 03 LAST_NAME PIC X(10). 02 YEAR_OF_STUDY. 03 FIRST_SEM PIC XX. 03 SECOND_SEM PIC XX.

796


Define general trees?

553


Why sorting is done?

500






What is data structure and data type?

549


Explain recursive function & what is the data structures used to perform recursion?

624


How does dynamic memory allocation help in managing data?

1070


Is arraylist synchronized?

542


Which is better hashmap or treemap?

503


Can a null element added to a treeset or hashset?

469


What is binary tree used for?

511


Write an algorithm to find middle element in the linked list.

538


Define b-tree of order m?

570


What are the applications of graph data structure?

482