working quick sort in both directions