Good Afternoon,
I'm having trouble with a school assignment. The assignment entails:
Write the implementation of the function subsequence for the orderedArrayListType class. Also write a program to test your function.
Prototype:
bool orderedArrayListType::subSequence (orderedArrayListType &S,orderedArrayListType &L);
Definition: subsequence returns true if S is a subsequence of L, false otherwise. Where S is a subsequence of L if for every pair of elements x and y in S at positions i and j, respectively, i < j, and also are in L at positions k and l, respectively, then k < l.
So far I have this:
bool orderedArrayListType::subSequence(orderedArrayListType &S, orderedArrayListType &L)
02 {
string X, Y;
03 if (Y.length() > X.length())
04 swap(X,Y);
05 int S = X.length(),L=Y.length();
06 vector< vector<int> > c(2, vector<int>(L+1,0));
07 int i,j;
08 for (i=1;i<=S;i++)
09 {
10 for (j=1;j<=L;j++)
11 {
12 if (X[i-1]==Y[j-1])
13 c[1][j]=c[0][j-1]+1;
14 else
15 c[1][j]=max(c[1][j-1],c[0][j]);
16 }
17 for (j=1;j<=L;j++)
18 c[0][j]=c[1][j];
19 }
20 return (c[1][L]);