Help for Algorithm
Oct 17, 2012 at 9:04pm UTC
Hello! I need help to find the longest sublist from the same two lists. I came to the following algorithm, but does not work properly. If anyone has an idea can help.
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
//start1 and start2->basic lists
//start3 ->new list
void build(elem* start1, elem* start2)
{
elem *L1, *L2, *p1, *p2;
elem *Pomoshten=NULL;
int n(0), br(0);
for (L1=start1; L1; L1=L1->next)
{
p1=L1;
for (L2=start2; L2; L2=L2->next)
{
br=0;
p2=L2;
while (p1 && p2 && p1->key==p2->key)
{
br++;
Pomoshten=add(Pomoshten, p1->key);
p1=p1->next;
p2=p2->next;
}
if (br>n)
{
start3=NULL;//delete
start3=Pomoshten;
Pomoshten=NULL;//delete
n=br;
br=0;
}
br=0;
}
}
}
Last edited on Oct 17, 2012 at 9:05pm UTC
Topic archived. No new replies allowed.