source:
branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Problems.ProgramSynthesis/Push/Data/Tree/TreeNode.cs
@
15771
Last change on this file since 15771 was 15771, checked in by bburlacu, 6 years ago | |
---|---|
File size: 814 bytes |
Rev | Line | |
---|---|---|
[14777] | 1 | using System.Collections.Generic; |
2 | ||
[15771] | 3 | namespace HeuristicLab.Problems.ProgramSynthesis { |
[14777] | 4 | public class TreeNode<T> { |
5 | public T Value { get; set; } | |
6 | public IList<TreeNode<T>> Children { get; private set; } | |
[15017] | 7 | public int Count { get; private set; } |
[14777] | 8 | |
9 | public TreeNode() { | |
10 | Children = new List<TreeNode<T>>(); | |
[15017] | 11 | Count = 1; |
[14777] | 12 | } |
13 | ||
14 | public TreeNode(T value) : this() { | |
15 | Value = value; | |
16 | } | |
17 | ||
18 | public void Add(T value) { | |
[14908] | 19 | Children.Add(new TreeNode<T>(value)); |
[15017] | 20 | Count++; |
[14777] | 21 | } |
22 | ||
23 | public void AddNode(TreeNode<T> node) { | |
[14908] | 24 | Children.Add(node); |
[15017] | 25 | Count += node.Count; |
[14777] | 26 | } |
27 | ||
28 | public void ReplaceNode(int index, TreeNode<T> node) { | |
[15017] | 29 | Count -= Children[index].Count; |
[14777] | 30 | Children[index] = node; |
[15017] | 31 | Count += node.Count; |
[14777] | 32 | } |
33 | } | |
34 | } |
Note: See TracBrowser
for help on using the repository browser.