Monday, May 30, 2011

Part V :Depth First Search

v      Depth First Search
public static void Depth_First_Search(Node Start, Node Goal)
        {
            GetSucc x = new GetSucc();
            ArrayList children = new ArrayList();
            Stack Fringe = new Stack();
            Fringe.Push(Start);
            while (Fringe.Count != 0)
            {
                Node Parent = (Node)Fringe.Pop();
                Console.WriteLine("Node {0} Visited ", Parent.State);
                Console.ReadKey();
                if (Parent.State == Goal.State)
                {
                    Console.WriteLine();
                    Console.WriteLine("Find Goal   " + Parent.State);
                    break;
                }//end if
                children = x.GetSussessor(Parent.State);
                for (int i = 0; i < children.Count; i++)
                {
                    int State = (int)children[i];
                    Node Tem = new Node(State, Parent);
                    Fringe.Push(Tem);
                }//end for
            }//end while
        }//end method

No comments:

Post a Comment