java bubble sort short circuit

Solutions on MaxInterview for java bubble sort short circuit by the best coders in the world

showing results for - "java bubble sort short circuit"
Franco
10 Oct 2017
1public static void BubbleSortShortSC(int[] array)
2    {
3        for(int i = 0; i < array.length - 1; i++)
4        {
5            boolean sorted = true;
6            for (int j = 0; j < array.length - i - 1; j++)
7            {
8                if(array[j] < array[j+1])
9                {
10                    int temp = array[j];
11                    array[j] = array[j+1];
12                    array[j+1] = temp;
13                    sorted = false;
14                }
15            }
16            if (sorted)
17            	break;
18        }
19    }