Monday, June 8, 2015

Haskell 99 Problem 28

Problem

Please find the problem here.

Solution:

Please see the solution as follow:

Initially I thought this is a simple sorting problem, so I used quicksort. But there is a catch, isn't there always a catch? Turn out the expectation requires a stable sort, so I implemented mergesort as well. Be careful with the key equals case in merge, in order to be stable, we need to make sure we pick the value from the first list in that case to be stable.

No comments :

Post a Comment