I have a problem creating a tree from a list of strings. Here is my input:
IReadOnlyList<IReadOnlyList<string>> listeDesParcours = new List<IReadOnlyList<string>>
{
new List<string>
{
"Produit","Sinistre","Particulier","Auto","RC"
},
new List<string>
{
"Produit","Sinistre","Entreprise","Auto","2roues"
},
new List<string>
{
"Produit","reclamation","Particulier","Moto","PP"
},
new List<string>
{
"Produit","reclamation","Entreprise","Auto","TT"
},
new List<string>
{
"Produit","reclamation","Entreprise","Auto","PP"
},
new List<string>
{
"Produit","souscription","Salarie","Aviation"
},
new List<string>
{
"Produit","souscription","Salarie","Aviation","Airbus"
},
new List<string>
{
"Produit","reclamation","Reclamation tout court"
},
new List<string>
{
"Produit","Produit tout court"
},
new List<string>
{
"Produit","Sinistre","Entreprise","Auto","5roues"
}
};
As you can see, this is a list of a list of strings, and I want to get a tree from it, here is my object that I want to return at the end
public class Node
{
public string Value { get; set; }
public List<Node> Childs { get; set; }
}
and that’s exactly how I want to get the structure
RootElement
|
___________________________Produit__________________________
/ | \
__sinistre___________ reclamation_______ Souscription
| \ / \ |
entreprise particulier entreprise particulier Salarie______________
| | | | | \
auto auto auto auto Marine Aviation__
/ \
Airbus Boing
Can someone point me to a recursive method that allows me to populate a tree from a list of list?
Thanks in advance
EDIT : After the last comment, I want to clarify that I want to get an object of type Node that I created ... however my input is a list of list of strings