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
public void sortArrayUsingSingleLoop(int[] intArray) { int temp; boolean swap = false; for(int i=0;iintArray[i+1]){ temp=intArray[i]; intArray[i]=intArray[i+1]; intArray[i+1]=temp; swap=true; } if(swap &&i==intArray.length-2){ i=-1;swap=false; } } }