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

Why we use linked list?

681


Can we declare array size as a negative number?

776


Explain merge sort algorithms.

766


Define a set?

712


Can list contain null values?

638


What do you mean by Runtime Error

764


What are the disadvantages of circular list?

691


What do you mean by back edge?

804


What is the most used data structure?

635


Define parent node?

726


What is a hash in programming?

670


What is worst case complexity algorithm?

667


What is the difference between a push and a pop?

721


How do you find the complexity of a selection sort?

670


When should structures be passed by values or by reference?

758