-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfront and back search.cpp
66 lines (47 loc) · 1.07 KB
/
front and back search.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// CPP program to implement front and back
// search
#include<iostream>
using namespace std;
bool search(string arr[4][3], int n, string x[1][3])
{
// Start searching from both ends
int front = 0, back = n - 1;
// Keep searching while two indexes
// do not cross.
while (front <= back)
{
int l = 0;
int loop;
for (int j=0;j<3;j++)
{
if (arr[front][j] == x[0][j] || arr[back][j] == x[0][j]) {
if(arr[front][j] == x[0][j])
{
loop=front;
}
if(arr[back][j] == x[0][j])
{
loop=back;
}
l++; }
}
if(l == 3)
{
return true;
}
front++;
back--;
}
return false;
}
int main()
{
string arr[4][3] = {{"Thokar","city Terminal","5"}, {"canal","uet","9"}, {"uet","emporium","9"}, {"packages", "fortress", "5"}};
string x[1][3] = {{"Thokar","city Terminal","5"}};
int n = sizeof(arr)/sizeof(arr[0]);
if (search(arr, n, x))
cout << "Yes";
else
cout << "No";
return 0;
}