当前位置: 首页>>代码示例>>C#>>正文


C# PriorityQueue.isEmpty方法代码示例

本文整理汇总了C#中System.Collections.Generic.PriorityQueue.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.isEmpty方法的具体用法?C# PriorityQueue.isEmpty怎么用?C# PriorityQueue.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Generic.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.isEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            // Print the top M lines in the input stream.
            Console.Write("Write Lenth : ");
            int M = int.Parse(Console.ReadLine());
            Console.Write("Write Del max(True) or min(False) : ");
            bool b = false;
            bool.TryParse(Console.ReadLine(),out b);

            PriorityQueue<int> pq = new PriorityQueue<int>(M,b);

            Console.WriteLine("Insert Queue : ");
            for(int i=0;i<M;i++)
                pq.Insert(int.Parse(Console.ReadLine()));

            Stack<int> stack = new Stack<int>();

            while (!pq.isEmpty())
                stack.push(pq.Del());

            Console.WriteLine("\n\t OutPut Stack");
            while(!stack.isEmpty())
                Console.WriteLine(stack.pull());

            Console.ReadKey();
        }
开发者ID:kaplunov93,项目名称:Algorithms,代码行数:26,代码来源:Program.cs

示例2: crossing

        private PriorityQueue<Edge> pq; // crossing (and ineligible) edges

        #endregion Fields

        #region Constructors

        public LazyPrimMST(EdgeWeightedGraph G)
        {
            pq = new PriorityQueue<Edge>(G.V);
            marked = new bool[G.V];
            mst = new Queue<Edge>();
            visit(G, 0); // assumes G is connected (see Exercise 4.3.22)
            while (!pq.isEmpty())
            {
                Edge e = pq.Del(); // Get lowest-weight
                int v = e.either;
                int w = e.other(v); // edge from pq.
                if (marked[v] && marked[w])
                    continue; // Skip if ineligible.
                mst.Enqueue(e); // Add edge to tree.
                if (!marked[v])
                    visit(G, v); // Add vertex to tree
                if (!marked[w])
                    visit(G, w); // (either v or w).
            }
        }
开发者ID:kaplunov93,项目名称:Algorithms,代码行数:26,代码来源:LazyPrimMST.cs

示例3: Main

        static void Main(string[] args)
        {
            string input;
            string result;
            List<Node> closed = new List<Node>();
            PriorityQueue<Node> open = new PriorityQueue<Node>();

            Console.WriteLine("enter initial string set: ");
            input = Console.ReadLine();
            Console.WriteLine("Enter desired string set: ");
            result = Console.ReadLine();

            Node start = new Node(input);
            Node goal = new Node(result);

            start.G = 0; //set G to amount of nodes traversed aka priority
            start.SetH(goal); //set the h value based on the goal node's value

            Node current = start;
            open.Enqueue(current); //add current node into open list

            while (open.Peek() != goal)
            {
                //generate children based on items in open list (current)
                List<Node> Children = getChildren(current, closed, open);

                current = open.Dequeue(); //pop current node
                closed.Add(current); //add current node into closed list

                //Console.WriteLine(current.GameString);

                foreach (Node child in Children)
                {
                    //child.SetH(goal);
                    open.Enqueue(child);
                }

                if (current.Equals(goal))
                {
                    Console.WriteLine("found path:");
                    Node last = current;
                    List<Node> list = new List<Node>();
                    while (last.Parent != null)
                    {
                        list.Add(last);
                        last = last.Parent;
                    }
                    list.Add(last);
                    list.Reverse();
                    foreach (Node n in list)
                        Console.WriteLine(n.ToString());
                    break;
                }

                if (open.isEmpty())
                {
                    Console.WriteLine("failed to find path");
                    break;
                }

                if (Children == null)
                {
                    current = open.Dequeue(); //set first element of open list to current and pop
                    continue;
                }
            }
            Console.ReadKey(true);
        }
开发者ID:sseng,项目名称:ai,代码行数:68,代码来源:Program.cs


注:本文中的System.Collections.Generic.PriorityQueue.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。