I need to build a tree from hierarchical flat collection separated by dots (.) like namespaces in C# for example. Here are some entry values as a collection (ordered):
A0.A0.A0
A1
A1.A2
A2.A3.A3.A2
A3.A2
A3.A4.A5.A3
A3.A4.A5.A4
B0.B1.B0
B1.B2
B1.B2.B3
B1.B2.B4
This collection looks like namespaces in C#. So let's assume they are namespaces (as you can understand A.A.A.A namespace is really legal).
What I need?
I need a parent-child tree from this collection like this (note, we save some space concatenating some names in one):
A0.A0.A0
A1
A2
A2.A3.A3.A2
A3
A2
A4.A5
A3
A4
B0.B1.B0
B1.B2
B3
B4
In this case we will have only 6 root objects.
Here is our interface for our algorithm:
public interface IParentChild
{
IEnumerable<IParentChild> Children { get; set; }
string FullName { get; set; }
string Name { get; set; }
}
Any suggestions ?