Пример #1
0
        public static FTree <T> CreateR(Digit <T> frontDig,
                                        FTree <Node <T> > innerFT,
                                        List <T> backList //may be empty!
                                        )
        {
            if (backList.Count > 0)
            {
                return(new DeepFTree <T>(frontDig,
                                         innerFT,
                                         new Digit <T>(backList)
                                         ));
            }
            //else

            if (innerFT is EmptyFTree <Node <T> > )
            {
                return(FromSequence(frontDig.digNodes));
            }

            //else we must create a new intermediate tree
            var innerRight = innerFT.RightView();

            List <T> newlstBack = innerRight.last.theNodes;

            DeepFTree <T> theNewDeepTree =
                new DeepFTree <T>(frontDig,
                                  innerRight.ftInit,
                                  new Digit <T>(newlstBack)
                                  );

            return(theNewDeepTree);
        }
Пример #2
0
        public override FTree <T> App2(List <T> ts, FTree <T> rightFT)
        {
            if (!(rightFT is DeepFTree <T>))
            {
                FTree <T> resultFT = this;

                foreach (T t in ts)
                {
                    resultFT = resultFT.Push_Back(t);
                }

                return((rightFT is EmptyFTree <T>)
                          ? resultFT
                          : resultFT.Push_Back(rightFT.LeftView().head));
            }
            else // the right tree is also a deep tree
            {
                DeepFTree <T> deepRight = rightFT as DeepFTree <T>;

                List <T> cmbList = new List <T>(backDig.digNodes);

                cmbList.AddRange(ts);

                cmbList.AddRange(deepRight.frontDig.digNodes);

                FTree <T> resultFT =
                    new DeepFTree <T>
                        (frontDig,
                        innerFT.App2(FTree <T> .ListOfNodes(cmbList), deepRight.innerFT),
                        deepRight.backDig
                        );

                return(resultFT);
            }
        }
Пример #3
0
        public static FTree <T> Create(List <T> frontList,  //may be empty!
                                       FTree <Node <T> > innerFT,
                                       Digit <T> backDig
                                       )
        {
            if (frontList.Count > 0)
            {
                return(new DeepFTree <T>(new Digit <T>(frontList),
                                         innerFT,
                                         backDig
                                         ));
            }
            //else

            if (innerFT is EmptyFTree <Node <T> > )
            {
                return(FromSequence(backDig.digNodes));
            }

            //else we must create a new intermediate tree
            var innerLeft = innerFT.LeftView();

            List <T> newlstFront = innerLeft.head.theNodes;

            DeepFTree <T> theNewDeepTree =
                new DeepFTree <T>(new Digit <T>(newlstFront),
                                  innerLeft.ftTail,
                                  backDig
                                  );

            return(theNewDeepTree);
        }
Пример #4
0
        public override FTree <T> App2(List <T> ts, FTree <T> rightFT)
        {
            FTree <T> resultFT = rightFT;

            for (int i = ts.Count - 1; i >= 0; i--)
            {
                resultFT = resultFT.Push_Front(ts[i]);
            }

            return(resultFT.Push_Front(theSingle));
        }
Пример #5
0
        public override ViewR <T> RightView()
        {
            int lastIndex = backDig.digNodes.Count - 1;
            T   last      = backDig.digNodes[lastIndex];

            List <T> newBack = new List <T>(backDig.digNodes);

            newBack.RemoveAt(lastIndex);

            return(new ViewR <T>(FTree <T> .CreateR(frontDig, innerFT, newBack),
                                 last
                                 ));
        }
Пример #6
0
        public override ViewL <T> LeftView()
        {
            T head = frontDig.digNodes[0];

            List <T> newFront = new List <T>(frontDig.digNodes);

            newFront.RemoveAt(0);

            return(new ViewL <T>(head,
                                 FTree <T> .Create(newFront, innerFT, backDig)
                                 //new DeepFTree<T>(newDigs, innerFT, backDig)
                                 ));
        }
Пример #7
0
 public DeepFTree(Digit <T> frontDig, FTree <Node <T> > innerFT, Digit <T> backDig)
 {
     if (frontDig.digNodes.Count > 0)
     {
         this.frontDig = frontDig;
         this.innerFT  = innerFT;
         this.backDig  = backDig;
     }
     else
     {
         throw new Exception("The DeepFTree() constructor is passed an empty frontDig !");
     }
 }
Пример #8
0
        public override FTree <T> Merge(FTree <T> rightFT)
        {
            List <T> emptyList = new List <T>();

            return(App2(emptyList, rightFT));
        }
Пример #9
0
 public override FTree <T> Merge(FTree <T> rightFT)
 {
     return(rightFT.Push_Front(theSingle));
 }
Пример #10
0
 public override FTree <T> Merge(FTree <T> rightFT)
 {
     return(rightFT);
 }
Пример #11
0
 public abstract FTree <T> App2(List <T> ts, FTree <T> rightFT);
Пример #12
0
 public abstract FTree <T> Merge(FTree <T> rightFT);
Пример #13
0
 public ViewR(FTree <X> ftInit, X last)
 {
     this.ftInit = ftInit;
     this.last   = last;
 }
Пример #14
0
 public ViewL(X head, FTree <X> ftTail)
 {
     this.head   = head;
     this.ftTail = ftTail;
 }