interview icon indicating copy to clipboard operation
interview copied to clipboard

快排算法的疑问

Open la1den opened this issue 2 years ago • 3 comments

https://github.com/huihut/interview/blob/e10ff5f6983130006eab46308edc05427d2542e7/Algorithm/QuickSort.h#L63

为什么 left++ 之后不交换 arr[end] 呢,移动后的 left 的位置的元素应该只是大于等于 arr[end] 而不能确定是等于吧

la1den avatar Apr 03 '23 04:04 la1den

https://github.com/huihut/interview/blob/e10ff5f6983130006eab46308edc05427d2542e7/Algorithm/QuickSort.h#L63

为什么 left++ 之后不交换 arr[end] 呢,移动后的 left 的位置的元素应该只是大于等于 arr[end] 而不能确定是等于吧

left++根本不可能执行,因为要执行left++必须left停留在<mid的元素上,也就是说退出循环left++的循环,只能是left==right,那这时left的位置的元素已经是>mid的了

goldfishgggg avatar Aug 02 '23 15:08 goldfishgggg

    嗨,亲!谢谢你的来信,记得常联系哦!

w272628569 avatar Aug 02 '23 16:08 w272628569

您好,您所发送的邮件我已收到,但并不能代表着邮件已被读取或被正确理解。

w540665710 avatar Aug 02 '23 16:08 w540665710