So I was going through different sorting algorithms. But almost all the sorting algorithms require 2 loops to sort the array. The time complexity of Bubble sort & Insert
Sorting an array using java in Single Loop:
public int[] getSortedArrayInOneLoop(int[] arr) { int temp; int j; for (int i = 1; i < arr.length; i++) { j = i - 1; if (arr[i] < arr[j]) { temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; i = 1; } } return arr; }