public TwoThreeTree <T> SymmetricDifference(TwoThreeTree <T> B) { TwoThreeTree <T> ANB = Difference(B); //A\B TwoThreeTree <T> BNA = B.Difference(this); //B\A return(ANB.Union(BNA)); }
public TwoThreeTree <T> Union(TwoThreeTree <T> B) { if (B == null || B.Count == 0) { TwoThreeTree <T> R = new TwoThreeTree <T>(_comp); R._r = this._r; R._count = this._count; R._h = this._h; return(R); } ITree <T> T2 = (ITree <T>)B; TwoThreeTree <T> C = new TwoThreeTree <T>(_comp); LinkedStack <T> S1 = new LinkedStack <T>();//CHECK FOR S = Stack<T> LinkedStack <T> S2 = new LinkedStack <T>(); this._visitor.PostOrder(this, (n) => __NodesVals(n, ref S1));//SYMMETRIC ORDER (INORDER) this._visitor.PostOrder(T2, (n) => __NodesVals(n, ref S2)); while (!S1.IsEmpty()) { C.Add(S1.Top()); S1.Pop(); } while (!S2.IsEmpty()) { C.Add(S2.Top()); S2.Pop(); } return(C); }
//CHECK STATEMENTS(_h -= 1; h += 1;) IN METHODS __Delete0, __Insert0 //IF DISTINCT(__ComputeH, THE STATEMENTS) DELETE STATEMENTS AND UNCOMMENT METHOD __ComputeH //ELSE DELETE METHOD __ComputeH /* * private void __ComputeH(){ * if(_count <= 1){ * _h = 0; * } * else if(_count > 1 && _count <= 3){ * _h = 1; * } * else { * TwoThreeNode<T> node = _r; * Int32 h = 0; * while(node.FirstSon != null){ * node = node.FirstSon; * h++; * } * _h = h; * } * }*/ #region setOperators public TwoThreeTree <T> Intersection(TwoThreeTree <T> B) { if (B == null || B.Count == 0) { return(new TwoThreeTree <T>(_comp));//EMPTY TREE } ITree <T> T2 = (ITree <T>)B; TwoThreeTree <T> C = new TwoThreeTree <T>(_comp); LinkedStack <T> S1 = new LinkedStack <T>();//CHECK FOR S = Stack<T> LinkedStack <T> S2 = new LinkedStack <T>(); this._visitor.PostOrder(this, (n) => __NodesVals(n, ref S1));//SYMMETRIC ORDER (INORDER) this._visitor.PostOrder(T2, (n) => __NodesVals(n, ref S2)); while (!S1.IsEmpty() && !S2.IsEmpty()) { if (_comp.Compare(S1.Top(), S2.Top()) == 0) { C.Add(S1.Top()); S1.Pop(); S2.Pop(); } else if (_comp.Compare(S1.Top(), S2.Top()) < 0) { S2.Pop(); } else { S1.Pop(); } } return(C);//CHANGE TYPE -> MAKE NEW METHOD. }
public SortedLinkedList <T> SymmetricDifferenceList(TwoThreeTree <T> B) { SortedLinkedList <T> ANB = UnionList(B); //A OR B SortedLinkedList <T> BNA = IntersectionList(B); //A AND B. return(ANB.Difference(BNA)); //A OR B - (A AND B) }
public SortedLinkedList <T> MergeList(TwoThreeTree <T> B) { if (IntersectionList(B).Count != 0) { return(null);//UNDEFINED } return(UnionList(B)); }
public TwoThreeTree <T> Merge(TwoThreeTree <T> B) { if (Intersection(B)._count != 0) { return(null);//UNDEFINED } return(Union(B)); }
public bool Overlaps(IEnumerable <T> other) { TwoThreeTree <T> B = new TwoThreeTree <T>(_comp); B.AddRange(other); B = Intersection(B);//A AND B return(B._count != 0); }
public bool SetEquals(IEnumerable <T> other) { if (other == null) { return(false); } TwoThreeTree <T> B = new TwoThreeTree <T>(_comp); B.AddRange(other); return(Equals(B)); }
public TwoThreeTree <T> Difference(TwoThreeTree <T> B) { if (B == null || B.Count == 0) { TwoThreeTree <T> R = new TwoThreeTree <T>(_comp); R._r = this._r; R._count = this._count; R._h = this._h; return(R); } ITree <T> T2 = (ITree <T>)B; TwoThreeTree <T> C = new TwoThreeTree <T>(_comp); LinkedStack <T> S1 = new LinkedStack <T>();//CHECK FOR S = Stack<T> LinkedStack <T> S2 = new LinkedStack <T>(); this._visitor.PostOrder(this, (n) => __NodesVals(n, ref S1));//SYMMETRIC ORDER (INORDER) this._visitor.PostOrder(T2, (n) => __NodesVals(n, ref S2)); bool flag = true; while (!S1.IsEmpty()) { if (flag && S2.IsEmpty()) { flag = false; } if (flag && _comp.Compare(S1.Top(), S2.Top()) == 0) { S1.Pop(); S2.Pop(); } else if (flag && _comp.Compare(S1.Top(), S2.Top()) > 0) { C.Add(S1.Top()); S1.Pop(); } else { if (flag) { S2.Pop(); } else { C.Add(S1.Top()); S1.Pop(); } } } return(C); }
public void SymmetricExceptWith(IEnumerable <T> other) { if (other.Count() == 0) { return; } TwoThreeTree <T> B = new TwoThreeTree <T>(_comp); B.AddRange(other); B = SymmetricDifference(B); Clear(); AddRange((IEnumerable <T>)B); }
public void IntersectWith(IEnumerable <T> other) { TwoThreeTree <T> B = new TwoThreeTree <T>(_comp); B.AddRange(other); B = Intersection(B); if (B._count == 0) { Clear(); return; } Clear(); AddRange((IEnumerable <T>)B); }
public Boolean Equals(TwoThreeTree <T> B) { if (B == null) { return(false); } if (IntersectionList(B).Count == _count) { return(true); } else { return(false); } }
public override Boolean Equals(Object obj) { if (obj == null) { return(false); } TwoThreeTree <T> B = obj as TwoThreeTree <T>; if (B == null) { return(false); } else { return(Equals(B)); } }
public SortedLinkedList <T> DifferenceList(TwoThreeTree <T> B) { ITree <T> T2 = (ITree <T>)B; CSharpDataStructures.Structures.Lists.LinkedList <T> C = new CSharpDataStructures.Structures.Lists.LinkedList <T>(); LinkedStack <T> S1 = new LinkedStack <T>();//CHECK FOR S = Stack<T> LinkedStack <T> S2 = new LinkedStack <T>(); this._visitor.PostOrder(this, (n) => __NodesVals(n, ref S1));//POST ORDER (INORDER) this._visitor.PostOrder(T2, (n) => __NodesVals(n, ref S2)); bool flag = true; while (!S1.IsEmpty()) { if (flag && S2.IsEmpty()) { flag = false; } if (flag && _comp.Compare(S1.Top(), S2.Top()) == 0) { S1.Pop(); S2.Pop(); } else if (flag && _comp.Compare(S1.Top(), S2.Top()) > 0) { C.Add(S1.Top()); S1.Pop(); } else { if (flag) { S2.Pop(); } else { C.Add(S1.Top()); S1.Pop(); } } } return(new SortedLinkedList <T>((IEnumerable <T>)C, _comp)); }
public bool IsProperSubsetOf(IEnumerable <T> other) { if (other.Count() == 0) { return(false); } TwoThreeTree <T> B = new TwoThreeTree <T>(_comp); B.AddRange(other); TwoThreeTree <T> C = Difference(B);//A\B. Int32 c = C._count; if (c == 0 && B._count > _count) { return(true); } return(false); }
public bool IsSupersetOf(IEnumerable <T> other) { if (other.Count() == 0) { return(true); } TwoThreeTree <T> B = new TwoThreeTree <T>(_comp); B.AddRange(other); TwoThreeTree <T> C = B.Difference(this);//B\A. Int32 c = C._count; if (c == 0) { return(true); } return(false); }
public bool IsSubsetOf(IEnumerable <T> other) { if (other.Count() == 0 && _count == 0) { return(true); } else if (other.Count() == 0 && _count != 0) { return(false); } TwoThreeTree <T> B = new TwoThreeTree <T>(_comp); B.AddRange(other); B = Difference(B);//A\B. Int32 c = B._count; if (c == 0) { return(true); } return(false); }
public SortedLinkedList <T> UnionList(TwoThreeTree <T> B) { ITree <T> T2 = (ITree <T>)B; CSharpDataStructures.Structures.Lists.LinkedList <T> C = new CSharpDataStructures.Structures.Lists.LinkedList <T>(); LinkedStack <T> S1 = new LinkedStack <T>();//CHECK FOR S = Stack<T> LinkedStack <T> S2 = new LinkedStack <T>(); this._visitor.PostOrder(this, (n) => __NodesVals(n, ref S1));//POST ORDER (INORDER) this._visitor.PostOrder(T2, (n) => __NodesVals(n, ref S2)); while (!S1.IsEmpty()) { C.Add(S1.Top()); S1.Pop(); } while (!S2.IsEmpty()) { C.Add(S2.Top()); S2.Pop(); } return(new SortedLinkedList <T>((IEnumerable <T>)C, _comp)); }
//RETURNS SortedLinkedList<T> INSTEAD OF 2-3 TREE public SortedLinkedList <T> IntersectionList(TwoThreeTree <T> B) { if (B == null || B.Count == 0) { return(new SortedLinkedList <T>(_comp)); } ITree <T> T2 = (ITree <T>)B; CSharpDataStructures.Structures.Lists.LinkedList <T> C = new CSharpDataStructures.Structures.Lists.LinkedList <T>(); LinkedStack <T> S1 = new LinkedStack <T>();//CHECK FOR S = Stack<T> LinkedStack <T> S2 = new LinkedStack <T>(); this._visitor.PostOrder(this, (n) => __NodesVals(n, ref S1));//POST ORDER () this._visitor.PostOrder(T2, (n) => __NodesVals(n, ref S2)); while (!S1.IsEmpty() && !S2.IsEmpty()) { if (_comp.Compare(S1.Top(), S2.Top()) == 0) { C.Add(S1.Top()); S1.Pop(); S2.Pop(); } else if (_comp.Compare(S1.Top(), S2.Top()) < 0) { S2.Pop(); } else { S1.Pop(); } } return(new SortedLinkedList <T>((IEnumerable <T>)C, _comp)); }