-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongest common substring.cpp
More file actions
49 lines (36 loc) · 926 Bytes
/
Copy pathlongest common substring.cpp
File metadata and controls
49 lines (36 loc) · 926 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
44
45
46
47
48
49
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
void LCSUtil(int A[], int i, int B[], int j, stack<int> &s);
stack<int> LCS(int A[],int B[]);
stack<int> LCS(int A[], int B[]){
int n = sizeof(A)/sizeof(int);
int m = sizeof(B)/sizeof(int);
stack<int> myStack;
LCSUtil(A,n,B,m, myStack);
return myStack;
}
void LCSUtil(int A[], int i, int B[], int j, stack<int> &s){
if (i == 0 || j == 0)
{
break;
}
else if (A[i]==B[i])
{
s.push(A[i]);
LCS(A,i-1,B,j-1, s);
}
else
{
}
int main() {
int A[] = {0,1,2,3,4,6,7};
int B[] = {0,0,2,2,4,4,7};
stack<int> lcs = LCS(A,B);
while (!lcs.empty()){
cout << lcs.top() <<", ";
lcs.pop();
}
cin.get();
}