Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverseArray #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions dsa-roadmaps/Love Babbar Questions/Arrays/reverseArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Recursive C++ program to reverse an array
#include <bits/stdc++.h>
using namespace std;

/* Function to reverse arr[] from start to end*/
void rvereseArray(int arr[], int start, int end)
{
if (start >= end)
return;

int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;

// Recursive Function calling
rvereseArray(arr, start + 1, end - 1);
}


/* Utility function to print an array */
void printArray(int arr[], int size)
{
for (int i = 0; i < size; i++)
cout << arr[i] << " ";

cout << endl;
}

/* Driver function to test above functions */
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6};

// To print original array
printArray(arr, 6);

// Function calling
rvereseArray(arr, 0, 5);

cout << "Reversed array is" << endl;

// To print the Reversed array
printArray(arr, 6);

return 0;
}