Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two vectors, in C++

Tags:

c++

This is my code:

#include <algorithm>
void f() {
    int[] a = {1, 2, 3, 4};
    int[] b = {1, 2, 100, 101};
    // I want to do something like this:
    // int* found = compare(a[0], a[3], b[0]);
    // in order to get a pointer to a[2]
}

Maybe I missed this algorithm in the manual… Please help :)

like image 742
yegor256 Avatar asked Dec 22 '22 02:12

yegor256


2 Answers

Look at std::mismatch

like image 137
mmmmmm Avatar answered Jan 05 '23 00:01

mmmmmm


Sort your array and use mismatch.

like image 45
yesraaj Avatar answered Jan 04 '23 23:01

yesraaj