Skip to content

Commit

Permalink
update(cpp-stl): usage of std::equal algorithm
Browse files Browse the repository at this point in the history
issue #104
  • Loading branch information
sabertazimi committed Nov 23, 2018
1 parent 17c6cf2 commit f339a63
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions language/cpp/cppBasicNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,34 @@ lexicographical_compare
mismatch
```

```cpp
template<class InputIt1, class InputIt2>
bool equal(
InputIt1 first1,
InputIt1 last1,
InputIt2 first2
) {
for (; first1 != last1; ++first1, ++first2) {
if (!(*first1 == *first2)) {
return false;
}
}

return true;
}
```

```cpp
bool is_prefix(const std::string& s, const std::string& of) {
if (s.size() > of.size()) return false;
return std::equal(s.begin(), s.end(), of.begin());
}

bool is_palindrome(const std::string& s) {
return std::equal(s.begin(), s.begin() + s.size() / 2, s.rbegin());
}
```
### Search Algortihms
```cpp
Expand Down

0 comments on commit f339a63

Please sign in to comment.