C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Multi-property sort is inverting elements

By : Yuval Dolev
Date : November 22 2020, 10:33 AM
hope this fix your issue Your comparison functions are both broken. Neither implements the necessary strict weak ordering that std::stable_sort requires. Specifically,
Irreflexivity: f(x, x) must be false. Antisymmetry : f(x, y) implies !f(y, x)
code :
``````bool DecreasingA(const Data & a, const Data & b) {
return a.A > b.A;  // > instead of >=
}

bool DecreasingB(const Data & a, const Data & b) {
if (a.B == b.B)   // both equal, so a does not precede b
return false;
if (b.B)          // b.B is true and a.B is false, so a does not precede b
return false;
return true;      // a.B is true and b.B is false, so a does precede b
}
``````

Share :

## Inverting a BOOL property without using dot syntax

By : Jérémie Breda
Date : March 29 2020, 07:55 AM
wish helps you In this line of code I am reversing a BOOL value: , [someObject setBoolValue:![someObject boolValue]];

## Inverting List Elements in Haskell

Date : March 29 2020, 07:55 AM
it fixes the issue Here's one way to do this:
First we define a function to invert one list (if it has two elements; otherwise we return the list unchanged):
code :
``````invertOne :: [a] -> [a]
invertOne [x, y] = [y, x]
invertOne xs = xs
``````
``````invert :: [[a]] -> [[a]]
invert xs = map invertOne xs
``````

## Haskell: Multi-property sort is not generic enough

By : Pop Romany
Date : March 29 2020, 07:55 AM
To fix the issue you can do Since we have Monoid Ordering and instance Monoid b => Monoid (a -> b) in Prelude, we also have Monoid (a -> a -> Ordering) by iterating the function instance twice. This lets us solve the issue quite simply, without existentials:
code :
``````import Data.Ord (Ordering, comparing)
import Data.List (sortBy)
import Data.Monoid ((<>), mconcat)

data Row = Row {
shortListed :: Bool,
cost :: Float,
distance1 :: Int,
distance2 :: Int
} deriving (Show, Eq)

asc, desc :: Ord b => (a -> b) -> a -> a -> Ordering
asc  = comparing
desc = flip . asc

list :: [Row]
list = [Row False 0 10 20, Row True 10 30 40]

list' :: [Row]
list' = sortBy (asc shortListed <> desc cost <> asc distance1) list
``````
``````orderBy :: [a -> a -> Ordering] -> [a] -> [a]
orderBy = sortBy . mconcat

list'' :: [Row]
list'' = orderBy [asc shortListed, desc cost, asc distance1] list
``````

## Sort by elements in multiple layers of multi-layered tuple - Python

By : XuanYu Wang
Date : March 29 2020, 07:55 AM
help you fix your problem I have a tuple of tuples of tuples and I want to sort it first by the second element, then first, then third of the lowermost layer and iteratively do this for each tuple of the middle layer. , Try this:
code :
``````sortedSample = sorted(sampleToBeSorted, key= lambda x:[(i[1],i[0],i[2]) for i in x])
``````
``````[(('A', 31, 'B'), ('D', 32, 'B')),
(('C', 31, 'A'), ('B', 24, 'C'), ('C', 33, 'B')),
(('D', 31, 'A'), ('D', 32, 'B'), ('C', 29, 'B'), ('D', 216, 'C')),
(('D', 31, 'A'), ('D', 52, 'B')),
(('D', 40, 'B'), ('A', 32, 'C')),
(('D', 52, 'B'), ('D', 32, 'B'))]
``````

## How to multi-sort elements in a List

By : Ben Smith
Date : March 29 2020, 07:55 AM
hope this fix your issue How can I sort a list of 3 variables? , Try like this:-