我有一个字符串列表,其形式为XxX,其中X是最多4位数的数字(它们是(像素)x(像素)中的图像大小).
例如:
["192x192","64x84","96x96","64x64","292x192","32x32","64x12"]
Run Code Online (Sandbox Code Playgroud)
使用mySort函数,它只是插入排序,只查看最多x的数字:
mysort [] = []
mysort [x] = [x]
mysort (x:xs) = insert (mysort xs)
where insert [] = [x]
insert (y:ys) | takeUntilX x <= takeUntilX y = x : y : ys
| otherwise = y : insert ys
Run Code Online (Sandbox Code Playgroud)
我明白了:
["192x192","292x192","32x32","64x84","64x64","64x12","96x96"]
Run Code Online (Sandbox Code Playgroud)
哪个只是部分排序,所有排序的"64x**"以原始顺序重新映射但我希望它们也被排序,所以我得到这个:
["192x192","292x192","32x32","64x12","64x64","64x84","96x96"]
Run Code Online (Sandbox Code Playgroud)
什么是更好的解决方案 - 修改函数mySort或编写一个新的函数来排序部分排序的列表?你能告诉我如何做的基本想法吗?