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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started