Last active
August 29, 2015 14:07
-
-
Save Mooophy/c9d820db086456784374 to your computer and use it in GitHub Desktop.
made for a question on SO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! | |
//! @author Yue Wang | |
//! @date 15 Oct 2014 | |
//! @note for a question on SO: | |
//! http://stackoverflow.com/questions/26353067/how-to-recursively-compare-vectors/26359781#26359781 | |
//! | |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
/** | |
* @brief find_contiguous_block | |
* @complx O(n) | |
*/ | |
template<typename Iter> | |
bool find_contiguous_block(Iter first_a, Iter last_a, Iter first_b, Iter last_b) | |
{ | |
if(first_a == last_a) | |
return true; | |
auto found = std::find(first_b, last_b, *first_a); | |
if(found == last_b) | |
return false; | |
else | |
return find_contiguous_block(++first_a, last_a, found, last_b); | |
} | |
int main() | |
{ | |
std::vector<int> a{5,6,7}; | |
std::vector<int> b{1,2,3,4,5,6,7,8}; | |
std::cout << find_contiguous_block(a.begin(),a.end(),b.begin(),b.end()); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment