Stability of quicksort partitioning approach

后端 未结 8 2064
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 01:12

Does the following Quicksort partitioning algorithm result in a stable sort (i.e. does it maintain the relative position of elements with equal values):

  pa         


        
8条回答
  •  隐瞒了意图╮
    2020-12-05 01:26

    Any sort can be converted to a stable sort if you're willing to add a second key. The second key should be something that indicates the original order, such as a sequence number. In your comparison function, if the first keys are equal, use the second key.

提交回复
热议问题