|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
I have a bunch of nodes, which are abstract objects. Nodes have a
'parent' method, which returns the parent node, if there is one, or
'undef' if not. I can also compare two nodes to see if they are
equal. No node has more than one parent.
I want to write a function which, given a list of nodes, returns the
youngest common ancestor of all the nodes in the list, or undef if
there is no common ancestor. For example, given nodes organized like
this:
A M
/ \ |
B C N
/ \ |
D E F
|
G
The common ancestor of D and G is B;
the common ancestor of D and E is B;
the common ancestor of D and B is B;
the common ancestor of D and A is A;
the common ancestor of D and F is A;
the common ancestor of G and E is E;
the common ancestor of D and M is undefined
the common ancestor of N and M is M.
My function to do this is 18 lines long. This is way too much code.
I am sure there must be a simpler solution. Can anyone think of a
simpler solution?
-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|