Describe how you would reverse a single linked list.
Anónimo
template class LList { public: T val; LList* next; public: static void Reverse(LList** head) { if(NULL == (*head)) return; LList* headNew = NULL; LList* cur = *head; LList* next; while(cur) { // to insert the pointer to the current node at the head of a new list next = cur->next; cur->next = headNew; headNew = cur; cur = next; } *head = headNew; } };