rendered paste body public void sortByFour(){ if(_arr!=null){ int oIx = 0; int current = 0; int twoIx = _arr.length-1; int threeIx = twoIx; while(current <= twoIx){ switch (_arr[current] % 4){ case 0: swap (current, oIx); current++; oIx++; break; case 1: current++; break; case 2: swap(current, twoIx); twoIx--; break; case 3: swap(twoIx, current); swap(twoIx, threeIx); twoIx--; threeIx--; break; } } } } private void swap(int a,int b){ if(_arr!=null && a<_arr.length && b<_arr.length){ int tmp = _arr[a]; _arr[a] = _arr[b]; _arr[b] = tmp; } }