package Recursion;
public class BubbleSort {
public static void main(String[] args) {
int [] arr = {50,40,30,20,10};
int si=0;
int li=arr.length-1;
Bubble(arr,si,li);
display(arr);
}
public static void Bubble(int []arr, int si, int li)
{
//base case
if(li==0)
{
return;
}
if(si == li)
{
Bubble(arr,0,li-1);
return;
}
if(arr[si] > arr[si+1])
{
int temp = arr[si];
arr[si] = arr[si+1];
arr[si+1] = arr[si];
}
Bubble(arr,si+1,li);
}
public static void display(int [] arr)
{
for(int i=0; i <= arr.length-1;i++)
{
System.out.println(arr[i]);
}
}
}
output is coming
10
10
10
10
10
but it should be
10
20
30
40
50