Question

NEED ASAP. Written in C++ Write a function that uses Recursion to copy a list

NEED ASAP. Written in C++

Write a function that uses Recursion to copy a list

0 0
Add a comment Improve this question Transcribed image text
Answer #1

please do upvote.If you have any problem do comment and i shall be happy to help you.Thanks for using homeworklib.

--------------------------------------
#include<stdio.h>
#include<iostream>


using namespace std;

void copy(int l1[],int l2[],int index)
{
   //just return if index<0
   if (index < 0)
   {
       return;
   }

   else
   {

       l2[index] = l1[index];

       index = index - 1;

       //recursive call
       copy(l1, l2, index);

   }
}

int main()
{
   //create two arrays
   const int size = 4;
   int l1[size] = { 10,20,30,40 };
   int l2[size] ;


   //call recursive function to copy l1 to l2
   copy(l1, l2, size - 1);

   //print l2
   for (int i = 0; i < size; i++)
   {

       cout << l2[i] << endl;
   }

   system("pause");//remove it if not required.it is used to prevent console in visual studio from closing
   return 0;

}

--------------------------------

Add a comment
Know the answer?
Add Answer to:
NEED ASAP. Written in C++ Write a function that uses Recursion to copy a list
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT