bool relazione( unsigned int a, unsigned int b )
{
return ((9*a + 5*b) % 14 == 0)
}
std::sort
per ordinare un vettore di unsigned int
?bool relazione( unsigned int a, unsigned int b )
{
unsigned int somma = (9*a + 5*b);
unsigned int h_ipotesi = somma / 14;
return (somma == h_ipotesi * 14);
}
true
, ma è altrimenti inutile. Ciò che conta è il valore di ritorno della funzione.cppreference ha scritto:comparison function object (i.e. an object that satisfies the requirements of Compare) which returns true if the first argument is less than (i.e. is ordered before) the second.
cppreference ha scritto:The typeT
satisfies Compare if
- The type
T
satisfiesBinaryPredicate
, and
GivenThe following expressions must be valid and have their specified effects:
comp
, an object of typeT
equiv(a, b)
, an expression equivalent to!comp(a, b) && !comp(b, a)
[th]Expression[/th] [th]Return type[/th] [th]Requirements [/th]
comp(a,b)
implicitly convertible to bool
Establishes strict weak ordering relation with the following properties:
- For all
a
,comp(a,a)==false
,- If
comp(a,b)==true
thencomp(b,a)==false
,- if
comp(a,b)==true
andcomp(b,c)==true
thencomp(a,c)==true
.equiv(a, b)
bool
Establishes equivalence relationship with the following properties
- For all
a
,equiv(a,a)==true
,- If
equiv(a,b)==true
, thenequiv(b,a)==true
,- If
equiv(a,b)==true
andequiv(b,c)==true
, thenequiv(a,c)==true
Torna a Algebra, logica, teoria dei numeri e matematica discreta
Visitano il forum: Nessuno e 1 ospite