mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-06 01:06:37 +02:00
Delete duplicate version os is_palindrome
This commit is contained in:
@ -36,7 +36,7 @@ namespace boost { namespace algorithm {
|
|||||||
/// For other sequences function will return false.
|
/// For other sequences function will return false.
|
||||||
/// Complexity: O(N).
|
/// Complexity: O(N).
|
||||||
template <typename BidirectionalIterator, typename Predicate>
|
template <typename BidirectionalIterator, typename Predicate>
|
||||||
bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p )
|
bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p)
|
||||||
{
|
{
|
||||||
if(begin == end)
|
if(begin == end)
|
||||||
{
|
{
|
||||||
@ -64,7 +64,7 @@ bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predi
|
|||||||
/// \return true if the entire sequence is palindrome
|
/// \return true if the entire sequence is palindrome
|
||||||
///
|
///
|
||||||
/// \param begin The start of the input sequence
|
/// \param begin The start of the input sequence
|
||||||
/// \param end One past the end of the input sequence
|
/// \param end One past the end of the input sequence
|
||||||
///
|
///
|
||||||
/// \note This function will return true for empty sequences and for palindromes.
|
/// \note This function will return true for empty sequences and for palindromes.
|
||||||
/// For other sequences function will return false.
|
/// For other sequences function will return false.
|
||||||
@ -72,26 +72,8 @@ bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predi
|
|||||||
template <typename BidirectionalIterator>
|
template <typename BidirectionalIterator>
|
||||||
bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end)
|
bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end)
|
||||||
{
|
{
|
||||||
if(begin == end)
|
return is_palindrome(begin, end,
|
||||||
{
|
std::equal_to<typename std::iterator_traits<BidirectionalIterator>::value_type> ());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
--end;
|
|
||||||
while(begin != end)
|
|
||||||
{
|
|
||||||
if(!(*begin == *end))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
++begin;
|
|
||||||
if(begin == end)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
--end;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \fn is_palindrome ( const R& range )
|
/// \fn is_palindrome ( const R& range )
|
||||||
@ -123,7 +105,6 @@ bool is_palindrome(const R& range, Predicate p)
|
|||||||
return is_palindrome(boost::begin(range), boost::end(range), p);
|
return is_palindrome(boost::begin(range), boost::end(range), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// \fn is_palindrome ( const char* str )
|
/// \fn is_palindrome ( const char* str )
|
||||||
/// \return true if the entire sequence is palindrome
|
/// \return true if the entire sequence is palindrome
|
||||||
///
|
///
|
||||||
@ -134,14 +115,11 @@ bool is_palindrome(const R& range, Predicate p)
|
|||||||
/// Complexity: O(N).
|
/// Complexity: O(N).
|
||||||
bool is_palindrome(const char* str)
|
bool is_palindrome(const char* str)
|
||||||
{
|
{
|
||||||
if(str == nullptr)
|
if(!str)
|
||||||
{
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return is_palindrome(str, str + strlen(str));
|
return is_palindrome(str, str + strlen(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// \fn is_palindrome ( const char* str, Predicate p )
|
/// \fn is_palindrome ( const char* str, Predicate p )
|
||||||
/// \return true if the entire sequence is palindrome
|
/// \return true if the entire sequence is palindrome
|
||||||
///
|
///
|
||||||
@ -154,13 +132,10 @@ bool is_palindrome(const char* str)
|
|||||||
template<typename Predicate>
|
template<typename Predicate>
|
||||||
bool is_palindrome(const char* str, Predicate p)
|
bool is_palindrome(const char* str, Predicate p)
|
||||||
{
|
{
|
||||||
if(str == nullptr)
|
if(!str)
|
||||||
{
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return is_palindrome(str, str + strlen(str), p);
|
return is_palindrome(str, str + strlen(str), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif // BOOST_ALGORITHM_IS_PALINDROME_HPP
|
#endif // BOOST_ALGORITHM_IS_PALINDROME_HPP
|
||||||
|
Reference in New Issue
Block a user