I wrote the bubble sort code by regression as shown below and its working
public static void Bubblesort(int[] arr, int si, int li) {
if(si>=li) {
return;
}
if (arr[si]>arr[si+1]) {
int temp = arr[si];
arr[si]=arr[si+1];
arr[si+1]=temp;
}
Bubblesort(arr,si+1,li);
Bubblesort(arr,0,li-1);
}
As you see there is slight difference from the one showed in video, the second time calling of Bubble sort is put under the if condition “if (arr[si]>arr[si+1])” but due to this small change is put another if condition checking if last index becomes zero. Why? I know that the code would give error if I dont put that if condition but could not get the logic behind it as according to me both codes should give the out put without that if condtion.