Optimized bubble sort with new array