Algorithm - combine multiple lists, resulting in unique list and retaining order
Posted
by hitch
on Stack Overflow
See other posts from Stack Overflow
or by hitch
Published on 2010-04-28T07:48:17Z
Indexed on
2010/04/28
7:53 UTC
Read the original article
Hit count: 306
I want to combine multiple lists of items into a single list, retaining the overall order requirements. i.e.:
1: A C E
2: D E
3: B A D
result: B A C D E
above, starting with list 1, we have ACE, we then know that D must come before E, and from list 3, we know that B must come before A, and D must come after B and A.
If there are conflicting orderings, the first ordering should be used. i.e.
1: A C E
2: B D E
3: F D
result: A C B D E F
3 conflicts with 2, therefore requirements for 2 will be used.
If ordering requirements mean an item must come before or after another, it doesn't matter if it comes immediately before or after, or at the start or end of the list, as long as overall ordering is maintained.
This is being developed using VB.Net, so a LINQy solution (or any .Net solution) would be nice - otherwise pointers for an approach would be good.
© Stack Overflow or respective owner