Reputation: 1
what's the difference between these two.
int find_set ( int v )
{
if ( v == parent [ v ] )
return v ;
return parent [ v ] = find_set ( parent [ v ] ) ;
}
And:
int find_set ( int v )
{
if ( v == parent [ v ] )
return v ;
parent [ v ] = find_set ( parent [ v ] ) ;
}
Upvotes: 0
Views: 93
Reputation: 35788
The difference, as stated by @Omri, is that the second has no return if the if statement does not execute, leaving you with (hopefully) a compiler error for a code path with no return value. Unlike languages like Ruby, the last statement of a C++ method or function is not implicitly the return value.
Upvotes: 4