-
Notifications
You must be signed in to change notification settings - Fork 33
/
3.36.cpp
39 lines (35 loc) · 823 Bytes
/
3.36.cpp
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
/*
* Exercise 3.36: Write a program to compare two arrays for equality. Write a
* similar program to compare two vectors.
*
* By Faisal Saadatmand
*/
#include <iostream>
#include <vector>
int main()
{
// compare two arrays for equality
int a[] = {10, 20, 30, 40, 50};
auto *aBeg = std::begin(a), *aEnd = std::end(a);
int b[] = {10, 20, 30, 40, 50};
auto *bBeg = std::begin(b), *bEnd = std::end(b);
while (aBeg < aEnd) {
if (*aBeg != *bBeg) {
break;
}
++aBeg;
++bBeg;
}
if (aBeg == aEnd && bBeg == bEnd)
std::cout << "equal\n";
else
std::cout << "unequal\n";
// compare two vectors for equality
std::vector<int> ivec1 = {10, 20, 30, 40, 50};
std::vector<int> ivec2 = {10, 20, 30, 40, 50, 60};
if (ivec1 != ivec2)
std::cout << "unequal\n";
else
std::cout << "equal\n";
return 0;
}