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

What is data binding in c++?

733


What is the difference between #import and #include?

811


Search for: what is pair in c++?

907


When are exception objects created?

822


What is functions syntax in c++?

865


What is an arraylist c++?

938


What is the difference between the indirection operator and the address of oper-ator?

853


Is c++ the hardest programming language?

859


What c++ library is string in?

818


What is the difference between strcpy() and strncpy()?

865


Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

1736


How do you differentiate between overloading the prefix and postfix increments?

856


Which one is better- macro or function?

889


Define namespace in c++?

861


Is swift faster than go?

914