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

) Singly-linked list: A simple list is implemented with node structure: struct n

ID: 3741498 • Letter: #

Question

) Singly-linked list: A simple list is implemented with node structure: struct node { int data; node *next; node(); }; node *L; If L is a pointer to the first item on a list, then the following is a recursive function for printing the list in reverse order: void rev(node *L) { if (L == NULL) return; rev(L->next); cout << L->data; return; } Modify this function to write another recursive function (you must use recursion, such as the one above): node *copy(node *L) { } to create a new duplicate copy of the original list and return a pointer to the new list.

Explanation / Answer

node *copy(node *L) { if(L == NULL) return; node *temp=(node *)malloc(sizeof(node)); temp->data=L->data; temp->next=copy(L->next); return temp; }