Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FUNCTION length(LIST list) : INT
- // returns number of nodes until the end of the list
- FUNCTION skip(LIST list, INT k) : LIST
- // return the sublist of list, skipping k nodes
- FUNCTION intersection(LIST list1, list2) : LIST
- // returns the sublist where the two lists intersects
- INT n1 = length(list1);
- INT n2 = length(list2);
- IF (n1 > n2) THEN
- list1 = skip(list1, n1-n2)
- ELSE
- list2 = skip(list2, n2-n1)
- WHILE (list1 != list2)
- list1 = skip(list1, 1)
- list2 = skip(list2, 1)
- RETURN list1
Add Comment
Please, Sign In to add comment