vector finish
This commit is contained in:
42
headers/lexicographical_compare.hpp
Normal file
42
headers/lexicographical_compare.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
#ifndef LEXICOGRAPHICAL_COMPARE_HPP
|
||||
# define LEXICOGRAPHICAL_COMPARE_HPP
|
||||
|
||||
namespace ft {
|
||||
|
||||
template <class InputIt1, class InputIt2>
|
||||
bool lexicographical_compare
|
||||
( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) {
|
||||
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (first2 == last2 || *first2 < *first1)
|
||||
return false;
|
||||
else if (*first1 < *first2)
|
||||
return true;
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return (first2 != last2);
|
||||
}
|
||||
|
||||
template <class InputIt1, class InputIt2, class Compare>
|
||||
bool lexicographical_compare
|
||||
( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp) {
|
||||
|
||||
while (first1 != last1)
|
||||
{
|
||||
if (first2 == last2 || comp(*first2, *first1))
|
||||
return false;
|
||||
else if (comp(*first1, *first2))
|
||||
return true;
|
||||
++first1;
|
||||
++first2;
|
||||
}
|
||||
return (first2 != last2);
|
||||
}
|
||||
|
||||
} // namespace ft
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user