public static void breathFirstSearch(GraphNode root, int x) { if(root.val == x) { System.Console.WriteLine("find in root"); return; } Queue queue = new Queue(); root.visited = true; queue.enqueue(root); while(queue.first!=null){ GraphNode c = (GraphNode) queue.dequeue(); foreach(GraphNode n in c.neighbors) { if(!n.visited){ System.Console.WriteLine(n.val +" "); n.visited = true; if(n.val == x) { System.Console.Write("Find "+n.val); return; } queue.enqueue(n); } } } }
/// <summary> /// Creates the config process stack. /// </summary> /// <param name="configs">The configs.</param> /// <param name="dependencyStack">The dependency stack.</param> /// <returns></returns> private Queue<Configuration> CreateConfigProcessQueue(RenderConfig renderConfig, Stack<Node<string>> dependencyStack) { Queue<Configuration> configQueue = new Queue<Configuration>(); while (dependencyStack.Count > 0) { Node<string> node = dependencyStack.Pop(); foreach (Configuration c in renderConfig.Configurations) { if (c.Name == node.Identity) { configQueue.Enqueue(c); } } } return configQueue; }