intersection of two circular lists

Hello everyone! Please help with writing a program. It's Very necessary. Write a program Intersection of two cyclic lists. Knowing that Intersection - the result contains elements that are simultaneously present in both data structures. I need in full program code. I'll be very grateful. Thanks!
Last edited on
Sounds like an interesting project.
There's the simple N2 solution:
1
2
3
4
5
6
7
for every item i in list1
    for every item j in list2
          if (i==j) {
               append i to result
          }
    }
}
if the lists are massive, you need to make one of them easy to search so the above goes back to near O(N). Its the same approach: take item in list 1, ask if it is in list 2, you are just making that inner loop go away with a little extra effort. If its just a homework or small problem, don't need to sweat that, but hopefully you can see that its identical logic
Topic archived. No new replies allowed.