Write a nonrecursive routine to reverse a singly linked
list in O(N) time.

Answer Posted / hasan ali mirza

list reverse(list L)
{
stack S;
position Lpos = first(L);
while(Lpos->element != NULL)
{
push(Lpos->element, S);
Lpos = Lpos->next;
}
makeEmpty(L);
Lpos = first(L);
while(isempty(S) == FALSE)
{
insert(pop(S), Lpos);
Lpos = Lpos->next;
}
return L;
}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to avoid a class from getting inherited but respective class should be able to instantiate ?

1470


Just a one miniute topics in English?

1317


Why does the 'divisibility by 3' rule work?

2629


is there any better model than jcb 3dx

1635


explain bug tracking system in detail.

1487






Show the forces acting on a ladder

579


compair and contrast procedrual and object oriented programming language

1315


What is the significance of superconductors?

595


Write a c pgm to print the letter as per given condition i.e.. if u give 4 out put should b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

1511


Briefly describe your ideal job?

3351


c# code, vb.net code language parity refers to what?

3062


consiteunts of indian railways

1733


what are the various height of GSM mount and its base width ashim.port@gmail.com

1400


A rectangular sheet dimensions a x b is to be made into an open-topped box by cutting a square of side h from each corner and folding the 4 sides up. Find the value of h which allows the maximum volume of the box?

725


sir , i am prparing for IOCL engineergin post please send me the old placement papers

1588