In: Computer Science
void printList(double * A, int start, int end ) { if (start == end) //base case { cout << A[start] << endl; } else //recursive case { cout << A[start] << endl; printList(A, start + 1, end); } } int main() {
double nums[] = { 13.8, 2.14, 51, 82, 3.14, 1.7, 4.89, 18, 5, 23.6, 17, 48, 5.6 };
printList(nums, 0, 12); //13.8 2.14 51 .... 48 5.6 cout << endl;
//HELP HERE: Using a recursive method on C++, reverse order of items in list //(No loops allowed) reverse(nums, 0, 12); printList(nums, 0, 12); //5.6 48 17 ... 2.14 13.8
return 0; }
#include <iostream> using namespace std; void printList(double * A, int start, int end ) { if (start == end) //base case { cout << A[start] << endl; } else //recursive case { cout << A[start] << endl; printList(A, start + 1, end); } } void reverse(double * A, int start, int end){ if(start<end){ double temp = A[start]; A[start] = A[end]; A[end] = temp; reverse(A,start+1,end-1); } } int main() { double nums[] = { 13.8, 2.14, 51, 82, 3.14, 1.7, 4.89, 18, 5, 23.6, 17, 48, 5.6 }; printList(nums, 0, 12); //13.8 2.14 51 .... 48 5.6 cout << endl; //HELP HERE: Using a recursive method on C++, reverse order of items in list //(No loops allowed) reverse(nums, 0, 12); printList(nums, 0, 12); //5.6 48 17 ... 2.14 13.8 return 0; }