Doubt in code for Bubble sort using recursion

#include
using namespace std;
void bubblesort(int a[], int j, int n){
if(n==0) return;
if(j==n-1) return bubblesort(a,0,n-1);

if(a[j]>a[j+1]) swap(a[j],a[j+1]);
bubblesort(a,j+1,n);
return; // If we do not write this return statement the code still runs so what is the purpose of this return??

}
int main() {
int a[]={5,4,3,1}, n=4;
bubblesort(a,0,n);
for(int i=0;i<n;i++) cout<<a[i]<<" ";
return 0;
}

hello @sahilkhan2312000131

it is redundant in this case.
incase of void functions adding return statement in last is optional.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

can we write bubblesort(a,0,n-1); for (j==n-1) condition instead of return bubblesort(a,0,n-1);

no why u want to replace if with for?
please share the complete code , that u want to write

#include
using namespace std;
void bubblesort(int a[], int j, int n){
if(n==0) return;
if(j==n-1) return bubblesort(a,0,n-1); // can we replace this statement with bubblesort(a,0,n-1);

if(a[j]>a[j+1]) swap(a[j],a[j+1]);
bubblesort(a,j+1,n);
return;
}
int main() {
int a[]={5,4,3,1}, n=4;
bubblesort(a,0,n);
for(int i=0;i<n;i++) cout<<a[i]<<" ";
return 0;
}

NO , ONLY IN THE END RETURN IS OPTIONAL , ELSE EVERYWHERE IT IS NEEDED