Ejemplo n.º 1
0
        public static void Traverse(Tour tour, Traversal tm, Visitor vm, Direction d, Filter f = null)
        {
            WriteHeader(tm.ToString() + " - " + vm.ToString() + " - " + d.ToString());

            if (f == null)
            {
                filter = v => true;
            }
            else
            {
                filter = f;
            }

            switch (vm)
            {
            case Visitor.Partition: tour.visit = StandardPartition; break;

            case Visitor.Conjugate: tour.visit = ConjugatedPartition; break;

            case Visitor.Reverse: tour.visit = ReversedPartition; break;

            case Visitor.ReverseConjugate: tour.visit = ReversedConjugatedPartition; break;

            default: tour.visit = PrintPartition; break;
            }

            switch (tm)
            {
            case Traversal.PreOrder:
                if (d == Direction.LeftRight)
                {
                    tour.PreorderLRTraversal();
                }
                else
                {
                    tour.PreorderRLTraversal();
                }
                break;

            case Traversal.InOrder:
                if (d == Direction.LeftRight)
                {
                    tour.InorderLRTraversal();
                }
                else
                {
                    tour.InorderRLTraversal();
                }
                break;

            case Traversal.PostOrder:
                if (d == Direction.LeftRight)
                {
                    tour.PostorderLRTraversal();
                }
                else
                {
                    tour.PostorderRLTraversal();
                }
                break;

            case Traversal.LevelOrder:
                if (d == Direction.LeftRight)
                {
                    tour.LevelorderLRTraversal();
                }
                else
                {
                    tour.LevelorderRLTraversal();
                }
                break;

            case Traversal.BranchOrder:
                if (d == Direction.LeftRight)
                {
                    tour.BranchorderLRTraversal();
                }
                else
                {
                    tour.BranchorderRLTraversal();
                }
                break;
            }
        }