Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How many pointers are required to reverse a link list?

Answer Posted / prits

Using 3 pointers:
curr, next, result pointers, curr points to current node,
next obviously points to the next node, result points to
the new reversed linked list

void reverse_single_linked_list(struct node** headRef)
{
struct node* result = NULL;
struct node* current = *headRef;
struct node* next;
while (current != NULL)
{
next = current->next; // tricky: note the next node
current->next = result; // move the node onto the result
result = current;
current = next;
}
*headRef = result;
}

Is This Answer Correct ?    14 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

why is iostream::eof inside a loop condition considered wrong?

1114


What is c++ and its features?

1077


What are default parameters? How are they evaluated in c++ function?

1225


What are the important differences between c++ and java?

1203


What is a buffer c++?

1108


What is extern c++?

1065


What is the oldest programming language?

1064


What are c++ templates used for?

1179


How does c++ sort work?

1027


What's the best free c++ profiler for windows?

1134


What is the difference between #define debug 0 and #undef debug?

1241


What is a tree in c++?

1024


Can c++ be faster than c?

1079


What is a pdb file?

1062


What are the various access specifiers in c++?

1087