-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm.hpp
82 lines (79 loc) · 2.95 KB
/
algorithm.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algorithm.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yismaili <yismaili@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/13 23:51:53 by yismaili #+# #+# */
/* Updated: 2023/03/15 00:32:42 by yismaili ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include "utils.hpp"
namespace ft {
// Compares the elements in the range [first1,last1) with those in the range
// beginning at first2, and returns true if all of the elements in both ranges match.
template< class InputIt1, class InputIt2 >
bool equal( InputIt1 first1, InputIt1 last1, InputIt2 first2)
{
while (first1 < last1)
{
if (*first1 != *first2){
return (false);
}
else{
return (true);
}
first1++;
first2++;
}
return (true);
}
template< class InputIt1, class InputIt2, class BinaryPredicate >
bool equal( InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p)
{
while (first1 < last1)
{
if (!p(*first1, *first2)){
return (false);
}
else{
return (true);
}
first1++;
first2++;
}
return (true);
}
//true if the first range compares lexicographically less than the second,
//and "comp " Binary function returns a value convertible to bool.
template< class InputIt1, class InputIt2 >
bool lexicographical_compare( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2 ){
while (first1 < last1){
if ((first2 == last2) || *first1 > *first2){
return (true);
}
if (*first2 > *first1){
return (false);
}
first1++;
first2++;
}
return (false);
}
template< class InputIt1, class InputIt2, class Compare >
bool lexicographical_compare( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp ){
while (first1 < last1 && first2 < last2){
if (comp(*first1, *first2)){
return (true);
}
if (comp(*first2, *first1)){
return (false);
}
first1++;
first2++;
}
return (false);
}
}