How to "interleave" two DataTables.
- by Brent
Take these two lists:
List 1
Red
Green
Blue
List 2
Brown
Red
Blue
Purple
Orange
I'm looking for a way to combine these lists together to produce:
List 3
Brown
Red
Green
Blue
Purple
Orange
I think the basic rules are these:
1) Insert on top the list any row falling before the first common row (e.g., Brown comes before the first common row, Red);
2) Insert items between rows if both lists have two items (e.g., List 1 inserts Green between Red and Blue); and
3) Insert rows on the bottom if the there's no "between-ness" found in 2 (e.g., List 2 inserts Orange at the bottom).
The lists are stored in a DataTable. I'm guessing I'll have to switch between them while iterating, but I'm having a hard time figuring out a method of combining the rows.
Thanks for any help.
--Brent