working and tested quick sort median element partition