Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Task 10*
- * We are given numbers N and M and the following operations:
- * N = N+1
- * N = N+2
- * N = N*2
- * Write a program that finds the shortest sequence of operations
- * from the list above that starts from N and finishes in M.
- * Hint: use a queue.
- * Example: N = 5, M = 16
- * Sequence: 5 ---> 6 ---> 8 ---> 16
- */
- namespace Task10Version2ShortestSequenceOfOperation.Common
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class TreeNode<T>
- {
- /// <summary>
- /// List with children of node.
- /// </summary>
- private List<TreeNode<T>> children;
- /// <summary>
- /// Initializes a new instance of the TreeNode<T> class.
- /// </summary>
- /// <param name="value">Value that keep node</param>
- public TreeNode(T value)
- {
- this.Value = value;
- this.children = new List<TreeNode<T>>();
- this.NodeTreeLevel = 0;
- }
- /// <summary>
- /// Gets or sets value of node
- /// </summary>
- public T Value { get; set; }
- /// <summary>
- /// Gets or sets node parent.
- /// </summary>
- public TreeNode<T> Parent { get; set; }
- /// <summary>
- /// Gets or sets tree level of node.
- /// </summary>
- public int NodeTreeLevel { get; set; }
- /// <summary>
- /// Adds node child.
- /// </summary>
- /// <param name="child">Child of type TreeNode</param>
- public void AddChild(TreeNode<T> child)
- {
- child.Parent = this;
- child.NodeTreeLevel = this.NodeTreeLevel + 1;
- this.children.Add(child);
- }
- /// <summary>
- /// Counts node children.
- /// </summary>
- /// <returns>Number of children</returns>
- public int CountChildren()
- {
- int count = this.children.Count;
- return count;
- }
- /// <summary>
- /// Get node child by index.
- /// </summary>
- /// <param name="index">Index of child.</param>
- /// <returns>Child on this index.</returns>
- public TreeNode<T> GetChild(int index)
- {
- return this.children[index];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement