Write a program to reverse a linked list?

Answer Posted / prakash d

struct node *ptr1,*ptr2,*ptr3;

ptr1=start; //pointer points to starting node.
ptr2=ptr1->next;
ptr3=ptr2->next;

ptr1->next=NULL;

ptr2->next=ptr1;

while(ptr3!=NULL)
{
ptr1=ptr2;
ptr2=ptr3;
ptr3=ptr3->next;
ptr2->next=ptr1;
}
start=ptr2;

Is This Answer Correct ?    13 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?

663


What is private, public and protected inheritance?

585


What is do..while loops structure?

613


Which programming language is best?

545


What does ios :: app do in c++?

549






Difference between struct and class in terms of access modifier.

691


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

603


Which is not an ANSII C++ function a) sin() b) tmpnam() c) kbhit()

999


What is the difference between passing by reference and passing a reference?

554


What are the extraction and insertion operators in c++? Explain with examples.

636


Write a Program to find the largest of 4 no using macros.

576


What is the auto keyword good for in c++?

615


What are the 2 main types of data structures?

580


What is namespace std; and what is consists of?

659


Is c++ a low level language?

509