public void Add(T data) { if (data.CompareTo(Data) <= 0) { if (Left == null) { Left = new Node(data); } else { Left.Add(data); } } else { if (Right == null) { Right = new Node(data); } else { Right.Add(data); } } }
/// <summary> /// adds a new node to this node or it's childs. /// Consider that adding a new node to the current node does a process of searching the proper location under the current node in order to add /// the inserted node to. if no proper location could be found, it just returns false, otherwise true. /// The node will be added to: the left side if it's value is less than the value of the current node, the right side if it's value was greater than the current node value /// </summary> /// <param name="node">the node to be attached to the current node (if possible). the node should be a single node</param> /// <returns>true if could find the proper location for the inserted node on the current node and it's childs</returns> public bool Add(Node node) { // if (!node.IsSingle)// if the node is not single do not add it!, you can change the code in order to make it addable! // throw new ArgumentException("the node should be single to be added."); var res = false; if (node.Value < Value) // add to left : it's value is less than the value of the current node { res = true; if (Left == null) { Left = node; } else { res = Left.Add(node); } IsChanged = true; } if (node.Value > Value) // add to right: it's value is greater than the value of the current node { res = true; IsChanged = true; if (Right == null) { Right = node; } else { res = Right.Add(node); } } return(res); }
public void Add(int data) { if (data <= value) { if (Left == null) { Left = new BinarySearchTree(data); } else { Left.Add(data); } } else { if (Right == null) { Right = new BinarySearchTree(data); } else { Right.Add(data); } } }
public void Add(T val) { if (val.CompareTo(Data) < 0) { if (Left == null) { Left = new BinaryNode <T>(val) { Parent = this } } ; else { Left.Add(val); } } if (val.CompareTo(Data) > 0) { if (Right == null) { Right = new BinaryNode <T>(val) { Parent = this } } ; else { Right.Add(val); } } }
public void Add(U newValue) { if (newValue.CompareTo(Value) < 0) { // The new value is smaller. Add it to the left subtree. if (Left is null) { Left = new SortedTree <U>(newValue); Left.Parent = this; } else { Left.Add(newValue); } } else { if (Right is null) { Right = new SortedTree <U>(newValue); Right.Parent = this; } else { Right.Add(newValue); } } }
public override void Add(TreeNode node) { if (node.Value >= Value) { if (Right == null) { Right = node; Right.Parent = this; } else { Right.Add(node); } } if (node.Value < Value) { if (Left == null) { Left = node; Left.Parent = this; } else { Left.Add(node); } } }
public void Add(T key) { Count++; if (!hasValue) { Value = key; hasValue = true; return; } if (key.CompareTo(Value) < 0) { if (Left == null) { Left = new AVLTree <T>(); } Left.Add(key); } else { if (Right == null) { Right = new AVLTree <T>(); } Right.Add(key); } Balance(); }
public void Add(int value) { if (Value == int.MinValue) { Value = value; return; } if (value > Value) { if (Right == null) { Right = new MyTree(value); } else { Right.Add(value); } } else { if (Left == null) { Left = new MyTree(value); } else { Left.Add(value); } } }
public BinarySearchTree <TNode> Add(TNode value) { int comparisonResult = value.CompareTo(Value); if (comparisonResult == 0) { return(this); } if (comparisonResult < 0) { // value < _value if (Left == null) { return(new BinarySearchTree <TNode>(Value, SingleNode(value), Right)); } return(new BinarySearchTree <TNode>(Value, Left.Add(value), Right)); } else { // value > _value if (Right == null) { return(new BinarySearchTree <TNode>(Value, Left, SingleNode(value))); } return(new BinarySearchTree <TNode>(Value, Left, Right.Add(value))); } }
/// <summary> /// Test completion data /// </summary> /// <param name="name">Student's name</param> /// <param name="testName">The name of the test</param> /// <param name="date">Date of passing the test</param> /// <param name="result">Test result</param> public void Add(string name, string testName, DateTime date, T result) { var node = new Node <T>(name, testName, date, result); if (node.CompareTo(Result) == -1) { if (Left == null) { Left = node; } else { Left.Add(name, testName, date, result); } } else { if (Right == null) { Right = node; } else { Right.Add(name, testName, date, result); } } }
public void Add(T insertValue) { int comparison = insertValue.CompareTo(Value); if (comparison == 0) { return; } if (comparison < 0) { if (Left == null) { Left = new TreeNode <T>(insertValue); } else { Left.Add(insertValue); } } else { if (Right == null) { Right = new TreeNode <T>(insertValue); } else { Right.Add(insertValue); } } }
public void Add(int value) { if (value < Value) { if (Left == null) { Left = new RBTree(value, this); } else { Left.Add(value); } } else { if (Right == null) { Right = new RBTree(value, this); } else { Right.Add(value); } } }
/// <summary> /// Constructor /// </summary> /// <param name="defeat">Page to go to on defeat</param> /// <param name="victory">Page to go to on victory</param> /// <param name="music">Music to be played</param> /// <param name="location">Location of the battle</param> /// <param name="left">Characters on the left in battle</param> /// <param name="right">Characters on the right in battle</param> public Battle(Page defeat, Page victory, Music music, string location, IEnumerable <Character> left, IEnumerable <Character> right, bool isUseTransition = false) : base(location) { this.wasExperienceGiven = false; this.loot = new Dictionary <Item, int>(); this.leftGraveyard = new HashSet <Character>(new IdentityEqualityComparer <Character>()); this.rightGraveyard = new HashSet <Character>(new IdentityEqualityComparer <Character>()); this.defeat = defeat; this.victory = victory; this.Music = music.GetDescription(); this.isUseTransition = isUseTransition; turnCount = 0; temporarySpells = new List <ISpellable>(); foreach (Character c in left) { Left.Add(c); } foreach (Character c in right) { Right.Add(c); } SetupTempSpells(); OnEnter += () => { if (!IsResolved) { Presenter.Main.Instance.StartCoroutine(startBattle()); } else { PostBattle(PlayerStatus); } }; }
public void Add(int value) { if (value == Value) // Prevents duplicate values by comparing incoming value against a node Value { return; } if (value < Value) // Checks against current node's Value for Left movement { if (Left == null) // No node below current Value { Left = new Node(value); } else { Left.Add(value); } } if (value > Value) // Checks against current node's Value for Right movement { if (Right == null) // No node below current Value { Right = new Node(value); } else { Right.Add(value); } } }
public void Add(int data) { if (data < Data) { if (Left == null) { Left = new Node(data, Count); Count++; } else { Left.Add(data); } } else { if (Right == null) { Right = new Node(data, Count); Count++; } else { Right.Add(data); } } }
public AVLNode <T> Add(T val) { if (val.CompareTo(Data) < 0) { if (Left == null) { Left = new AVLNode <T>(val) { Parent = this }; } else { Left = Left.Add(val); } } if (val.CompareTo(Data) > 0) { if (Right == null) { Right = new AVLNode <T>(val) { Parent = this }; } else { Right = Right.Add(val); } } return(CheckNodeBalance(this)); }
public void Add(Date data, RbNode <T> parent) { var node = new RbNode <T>(data, parent); if (node.Data.CompareTo(Data.Name) == -1) { if (Left == null) { Left = node; } else { Left.Add(data, Left); } } else { if (Right == null) { Right = node; } else { Right.Add(data, Right); } } Fix(parent, node); }
public void Add(T val) { if (val.CompareTo(Val) < 0) { if (Left == null) { Left = new BinaryTree <T>(val, this); } else if (Left != null) { Left.Add(val); } } else { if (Right == null) { Right = new BinaryTree <T>(val, this); } else if (Right != null) { Right.Add(val); } } }
public void Inflate(T inflateSize) { Left = Left.Subtract(inflateSize); Bottom = Bottom.Subtract(inflateSize); Right = Right.Add(inflateSize); Top = Top.Add(inflateSize); }
/// <summary> /// Constructs a new rule from the specified parameters /// </summary> /// <param name="left">The left hand side of the rule</param> /// <param name="right">The right hand side of the rule</param> public CfgRule(string left, IEnumerable <string> right) { Left = left; foreach (var s in right) { Right.Add(s); } }
public RightWrong() { foreach (Guess in List <Guess> ) { If(WordToGuess.Contains(Guess)) { Right.Add(Guess) }
private IEnumerator CheckForDeath() { foreach (Character c in GetAll()) { HashSet <Character> graveyard = null; bool isLeftGrave = false; if (Left.Contains(c)) { graveyard = leftGraveyard; isLeftGrave = true; } else { graveyard = rightGraveyard; isLeftGrave = false; } bool characterIsInGraveyard = graveyard.Contains(c); // Display death effect if (c.Stats.State == State.DEAD && !characterIsInGraveyard) { IList <Buff> dispellableOnDeath = c.Buffs.Where(b => b.IsDispellable).ToList(); foreach (Buff removableBuff in dispellableOnDeath) { c.Buffs.RemoveBuff(RemovalType.DISPEL, removableBuff); } Main.Instance.Sound.PlaySound("synthetic_explosion_1"); yield return(SFX.DoDeathEffect(c, 1f)); AddText(string.Format(CHARACTER_DEATH, c.Look.Name)); graveyard.Add(c); if (!c.HasFlag(Characters.Flag.PERSISTS_AFTER_DEFEAT)) { Left.Remove(c); Right.Remove(c); } } // Bring them back! (for revivals) if (c.Stats.State == State.ALIVE && characterIsInGraveyard) { graveyard.Remove(c); if (isLeftGrave) { Left.Add(c); } else { Right.Add(c); } } } }
// Задание 12: public void Add(int value) { // выход из рекурсии. Случай листа(нет потомков) if (Left == null && Right == null) { if (value <= Data) { Left = new Node(value); } else { Right = new Node(value); } return; } // случай сучка (есть только левый потомок) if (Left != null && Right == null) { if (value <= Data) { Left.Add(value); } else { Right = new Node(value); } return; } // случай сучка(есть только правый потомок) if (Left == null && Right != null) { if (value <= Data) { Left = new Node(value); } else { Right.Add(value); } return; } // случай сучка(есть оба потомка) if (Left != null && Right != null) { if (value <= Data) { Left.Add(value); } else { Right.Add(value); } return; } }
internal void AddRight(Node <T> item) { if (Right == null) { Right = item; item.Parent = this; return; } Right.Add(item); }
public override void Add(T item) { if (IsReadOnly) { throw new InvalidOperationException("This tree is read-only."); } if (item == null) { return; } // This node is available if (Node == null) { Node = new Node <T>(item); } // item is a descendant of this node else if (item.CompareTo(Node.Data) > 0) { if (Left == null) { Left = new BinaryTree <T> { Node = new Node <T>(item) }; return; } Left.Add(item); } // item is a ascendant of this node else if (item.CompareTo(Node.Data) < 0) { if (Right == null) { Right = new BinaryTree <T> { Node = new Node <T>(item) }; return; } Right.Add(item); } // Item is equal of this node else { Node.Amount++; } }
public IBinarySearchTree <K, V> Add(K key, V value) { AVLTree <K, V> result; if (key.CompareTo(Key) > 0) { result = new AVLTree <K, V>(Key, Value, Left, Right.Add(key, value)); } else { result = new AVLTree <K, V>(Key, Value, Left.Add(key, value), Right); } return(MakeBalanced(result)); }
private void OnBodyReceived(Gait gait) { switch (gait.POV) { case POV.Left: Left.Add(gait); Left.Refresh(); RaisePropertyChanged("Left"); break; case POV.Right: Right.Add(gait); Right.Refresh(); RaisePropertyChanged("Right"); break; } }
private Node <T> BalanceRight(Node <T> node) { Right = Right.Add(node); var displaced = Right.Left; if (Right.RightCount > LeftCount) { return(Right.ChangeLeft(ChangeRight(displaced))); } if (Right.LeftCount > LeftCount) { return(new Node <T>(displaced.Value, ChangeRight(displaced.Left), Right.ChangeLeft(displaced.Right))); } return(this); }
public void Add(int key, T data) { if (Key == null || Key == key) { Data = data; Key = key; return; } if (key < Key) { Left = createNewChildIfHeIsNull(Left, this); Left.Add(key, data); } else { Right = createNewChildIfHeIsNull(Right, this); Right.Add(key, data); } }
public void Add(T element) { if (FirstElement == null) { FirstElement = this; } if (Value.Equals(default(T))) { Value = element; } else if (element.CompareTo(Value) <= 0) { if (Left == null) { Left = new BinaryTree <T>(element, FirstElement); } else { Left.Add(element); } if (FirstElement.Value.Equals(Value)) { FirstElement = this; } } else { if (Right == null) { Right = new BinaryTree <T>(element, FirstElement); } else { Right.Add(element); } if (FirstElement.Value.Equals(Value)) { FirstElement = this; } } }