For the condition if(j==n-1) on line 26 how can we return when the function is of void type.
Bubble sort recursive array 2
@gkritika898
We make a recursive call over the bubbleSort2 function. Since the return type of this function is void only , we are not really returning anything.
Alternative you can write it as two seperate statements.
if(j == n-1) {
bubbleSort2(a,0,n-1) ;
return ;
}
This is equivalant to the original code
if(j == n-1) {
return bubbleSort2(a,0,n-1) ;
}
In both the expressions , the recursive call will be completed first and then the control will be returned to the parent call through the return statement. The return statement doesn’t return any value in either of them.
Okay now I got it. Thank you for the reply
@gkritika898
That’s good to know.
Please mark this doubt as resolved in your doubt section if your issue is resolved. Or let me know if you have any further queries regarding it so I can help you out.