reverse a array using recursion
Mon May 23 2022 05:59:06 GMT+0000 (Coordinated Universal Time)
Saved by
@sumit_tiwari
#include<iostream>
using namespace std;
void reverse(int arr[], int n, int s, int e) {
if (s > e) {
return;
}
swap(arr[s], arr[e]);
s++;
e--;
reverse(arr, n, s, e);
}
int main() {
int arr[4] = { 1,2,3,4 };
int s = 0;
int e = 3;
int n = 4;
reverse(arr, n, s, e);
for (int i = 0; i < n; i++) {
cout << arr[i]<<" ";
}
}
content_copyCOPY
Comments