/// <summary>
 /// Implements the DFT algorithm
 /// </summary>
 /// <param name="visitor"></param>
 /// <param name="v"></param>
 /// <param name="visited"></param>
 protected virtual void DepthFirstTraversal(IPrePostVisitor visitor, IVertex v, bool[] visited)
 {
     if (!visitor.IsDone)
     {
         visitor.PreVisit(v);
         visitor.Visit(v);
         visited[v.Number] = true;
         IEnumerator iEnumerator = v.Successors.GetEnumerator();
         try
         {
             while (iEnumerator.MoveNext())
             {
                 IVertex vertex = (IVertex)iEnumerator.Current;
                 if (!visited[vertex.Number])
                 {
                     DepthFirstTraversal(visitor, vertex, visited);
                 }
             }
         }
         finally
         {
             IDisposable iDisposable = iEnumerator as IDisposable;
             if (iDisposable != null)
             {
                 iDisposable.Dispose();
             }
         }
         visitor.PostVisit(v);
     }
 }
 /// <summary>
 /// DFT of the subtree
 /// </summary>
 /// <param name="visitor"></param>
 public override void DepthFirstTraversal(IPrePostVisitor visitor)
 {
     if (!base.IsEmpty)
     {
         visitor.PreVisit(mKey);
         Left.DepthFirstTraversal(visitor);
         visitor.Visit(mKey);
         Right.DepthFirstTraversal(visitor);
         visitor.PostVisit(mKey);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Performs a DFT of the tree
 /// </summary>
 /// <param name="visitor"></param>
 public virtual void DepthFirstTraversal(IPrePostVisitor visitor)
 {
     if (!visitor.IsDone && !base.IsEmpty)
     {
         visitor.PreVisit(Key);
         for (int i = 0; i < Degree; i++)
         {
             GetSubtree(i).DepthFirstTraversal(visitor);
         }
         visitor.PostVisit(Key);
     }
 }
        /// <summary>
        /// Performs a BFT of the graph with the given visitor and starting at the given vertex number.
        /// </summary>
        /// <param name="visitor"></param>
        /// <param name="start"></param>
        public virtual void BreadthFirstTraversal(IPrePostVisitor visitor, int start)
        {
            bool[] flags = new bool[mNumberOfVertices];
            for (int i = 0; i < mNumberOfVertices; i++)
            {
                flags[i] = false;
            }
            IQueue queue = new QueueAsLinkedList();

            queue.Enqueue(vertex[start]);
            flags[start] = true;
            while (!(queue.IsEmpty || visitor.IsDone))
            {
                IVertex vertex1 = (IVertex)queue.Dequeue();
                visitor.PreVisit(vertex1);
                Console.WriteLine("being in " + vertex1.Number);
                IEnumerator iEnumerator = vertex1.Successors.GetEnumerator();
                try
                {
                    while (iEnumerator.MoveNext())
                    {
                        IVertex vertex2 = (IVertex)iEnumerator.Current;
                        if (!flags[vertex2.Number])
                        {
                            queue.Enqueue(vertex2);
                            visitor.Visit(vertex2);
                            Console.WriteLine("engueueing " + vertex2.Number);
                            flags[vertex2.Number] = true;
                        }
                    }
                }
                finally
                {
                    IDisposable iDisposable = iEnumerator as IDisposable;
                    if (iDisposable != null)
                    {
                        iDisposable.Dispose();
                    }
                }
                visitor.PostVisit(vertex1);
            }
        }
Beispiel #5
0
 public override void DepthFirstTraversal(IPrePostVisitor visitor)
 {
     if (!IsEmpty)
     {
         visitor.PreVisit(key);
         Left.DepthFirstTraversal(visitor);
         visitor.InVisit(key);
         Right.DepthFirstTraversal(visitor);
         visitor.PostVisit(key);
     }
 }
Beispiel #6
0
 public virtual void DepthFirstTraversal(IPrePostVisitor visitor)
 {
     if (visitor.IsDone)
     {
         return;
     }
     if (!IsEmpty)
     {
         visitor.PreVisit(Key);
         for (int i = 0; i < Degree; i++)
         {
             GetSubtree(i).DepthFirstTraversal(visitor);
         }
         visitor.PostVisit(Key);
     }
 }