using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp4
{
public class TreeNode
{

public TN Data { get; set; }
public TreeNode Parent { get; set; }
public ICollection> Children { get; set; }
public string name;

public TreeNode(TN data, string N)
{
this.Parent = null;
this.Data = data;
this.Children = new LinkedList>();
this.name = N;
}

public TreeNode AddChild(TN child, string N)
{
TreeNode childNode = new TreeNode(child, N) { Parent = this };
this.Children.Add(childNode);
return childNode;
}

public TreeNode find_Node(string N)
{
TreeNode tmp = null;

if (name == N) return this;

for (int i = 0; i < Children.Count(); i++)
{
if (Children.ElementAt(i).name == N)
{
tmp = Children.ElementAt(i);
break;
}
else
{
tmp = Children.ElementAt(i).find_Node(N);
if (tmp != null) break;
}
}

return tmp;
}

public Collection> Get_Cumulative(string N, Collection> tnin, out bool test)
{
//Collection> tmp = new Collection>();


if (name == N)
{
tnin.Add(this);
test = true;
return tnin;
}

for (int i = 0; i < Children.Count(); i++)
{
bool tmptest = false;
Collection> hhh = Children.ElementAt(i).Get_Cumulative(N, tnin, out tmptest);
if (tmptest == true)
{
tnin = hhh;
tnin.Add(this);
test = true;
return tnin;
}
}

test = false;

return tnin;
}
}
}