using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AI { class Node { #region Constructor public Node(object data) { this.Data = data; } #endregion #region Properties private int _order; private object _data; private Node _parent; private List<Node> _childern = new List<Node>(); public object Data { get { return _data; } set { _data = value; } } public Node Parent { get { return _parent; } set { _parent = value; } } public List<Node> Children { get { return _childern; } set { _childern = value; } } public int Order { get { return _order; } set { _order = value; } } #endregion #region Methods public void AddChild(Node next_node) { next_node._order = this.Order + 1; next_node.Parent = this; this.Children.Add(next_node); } public void AddChild(object next_node_data) { Node next_node = new Node(next_node_data); AddChild(next_node); } #endregion } class Tree { #region Constructor public Tree(object root_data) { this.Root = new Node(root_data); this.Root.Order = 0; this.length = 1; } public Tree(Node root_node) { Root = root_node; } #endregion #region Properties private Node _root; private int _length; public Node Root { get { return _root; } set { _root = value; } } public int length { get { return _length; } set { _length = value; } } #endregion } }
Node primary = (currentNode.Order <= 1 ? currentNode : currentNode.Parent); while (primary.Order > 1) primary = primary.Parent;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)