How many pointers are required to reverse a link list?

Answer Posted / vivek

# 3 using 2 pointer:
void reverse(node* head_in_out)
{
if(head_in_out)
{
node* aCurr = head_in_out;
node* aNext = NULL;
while (aCurr)
{
head_in_out = aCurr->next;
aCurr->next = aNext;
aNext = aCurr;
aCurr = head_in_out;
}
head_in_out = aNext; // Bug in above 3rd answer.
}

}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe linked list using C++ with an example.

746


What are virtual functions in c++?

785


A mXn matrix is given and rows and column are sorted as shown below.Write a function that search a desired entered no in the matrix .with minimum complexity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

3335


What are guid? Why does com need guids?

668


Difference between inline functions and macros?

672






What is c++ hash?

729


Explain the difference between new() and malloc() in c++?

717


What is the use of data hiding?

685


What are the new features that iso/ansi c++ has added to original c++ specifications?

676


Carry out conversion of one object of user-defined type to another?

705


What is class syntax c++?

710


What is a binary file? List the merits and demerits of the binary file usagein C++.

832


Can a program run without main?

735


Why do we need c++?

689


How can an improvement in the quality of software be done by try/catch/throw?

678