Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Reverse a doubly linked list recursively using C++ This is what I have. What am

ID: 3719826 • Letter: R

Question

Reverse a doubly linked list recursively using C++

This is what I have. What am I doing wrong?

37 int reverse_list(node*head)

38 {

39 if(!head)

40 return 0;

41

42 node* temp = head->next;

43 head -> next = head -> previous;

44 head -> previous = temp;

45

46 if(!head->previous)

47 return 0;

48

49 return reverse_list(head-> previous);

50 }

Explanation / Answer

node * reverse_list(node* head) { if(head->next == NULL) { head->next = head->prev; return head; } else { node* temp = head->next; head->next = head->previous; head->previous = temp; return reverse_list(temp); } } // this is how you would call it node *new_root = reverse_list(root);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote