-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEquivalent Arrays.cpp
More file actions
43 lines (38 loc) · 892 Bytes
/
Equivalent Arrays.cpp
File metadata and controls
43 lines (38 loc) · 892 Bytes
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
40
41
42
43
//Mohammed Chowdhury
// CS 211 - 22C
// Assignment #2 - Equivalent arrays
/** write a function bool equivalent(int a[], int b[], int n) which takes two arrays a and b of
length n and returns true is they are shift equivalent and false otherwise.**/
#include <iostream>
using namespace std;
bool equivalent (int a[],int b[], int n);
int main(){
int a[] = {1,2,3,4,5};
int b[] = {3,4,5,1,2};
bool answer = equivalent ( a,b, 5);
cout << answer << endl;
return 0;
}
bool equivalent (int a[],int b[], int n){
bool same = true;
bool answer = false;
int temp;
for (int k = 0; k < n; k++) {
if (a[k] != b[k]) {
same = false;
break;
}
}
for (int j = 0; j < n; j++){
for (int i = 0 ; i < n ; i++){
temp = b[0];
b[i] = b[i+1];
b[n-1] = temp;
}
if (same) {
answer = true;
break;
}
}
return answer;
}