两个数组是否等于函数c ++

use*_*601 1 c++ arrays compare function

我正在尝试执行与数组比较的函数,如果它们相同则返回true.现在数组很简单,稍后会推进但我仍然坚持使用该testEqual功能.所以这是代码

int n = 5;
int array[5] = {5,10,3,4,7};
bubbleSort(pole,n);

int array2[5] = {3,4,5,7,10};
testEqual( array , array2 , "bubbleSort");
Run Code Online (Sandbox Code Playgroud)

这是testEqual我需要在阵列上重制的功能,但我不知道如何.

bool testEqual(int i1, int i2, const string testName) {
    bool myresult = (i1 == i2);
    return myresult;
}
Run Code Online (Sandbox Code Playgroud)

像bubbleSort这样的其他功能很好,我只需要重新制作testEqual.

Jar*_*d42 7

以下可能有所帮助

template <typename T, std::size_t N>
bool isEqual(const T (&lhs)[N], const T (&rhs)[N])
{
    return std::equal(std::begin(lhs), std::end(lhs), std::begin(rhs));
}
Run Code Online (Sandbox Code Playgroud)

如果您使用std::array,您可以免费使用.(而且语法更友好).