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


C# PriorityQueue.Count方法代码示例

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


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

示例1: PriorityQueue_Dequeue_NonRepeatedValues_Success

        public void PriorityQueue_Dequeue_NonRepeatedValues_Success()
        {
            // Arrange
            var priorityQueue = new PriorityQueue<int>();
            var values = new int[] { 10, 7, 6, 1, 2, 3, 5, 4, 9, 8 };
            var expected = "1,2,3,4,5,6,7,8,9,10";

            // Act
            foreach (var value in values)
            {
                priorityQueue.Enqueue(value);
            }

            var result = "";
            var index = 0;
            var lastIndex = priorityQueue.Count() - 1;

            while (!priorityQueue.IsEmpty())
            {
                var element = priorityQueue.Dequeue();

                result += index++ == lastIndex ?
                    string.Format("{0}", element.ToString()) : string.Format("{0},", element.ToString());
            }

            // Assert
            Assert.AreEqual(result, expected);
        }
开发者ID:nlehtola,项目名称:ict,代码行数:28,代码来源:PriorityQueueTests.cs

示例2: Main

    /* Task 1:  
     * Implement a class PriorityQueue<T> based on the data structure "binary heap".
     */

    static void Main(string[] args)
    {
        var prioQueue = new PriorityQueue<int>();

        prioQueue.Add(25);
        prioQueue.Add(15);
        prioQueue.Add(105);
        prioQueue.Add(5);
        prioQueue.Add(35);

        Console.WriteLine(prioQueue.Count());
        Console.WriteLine(prioQueue.Dequeue());
        Console.WriteLine(prioQueue.Dequeue());
        Console.WriteLine(prioQueue.Dequeue());
        Console.WriteLine(prioQueue.Dequeue());
    }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:20,代码来源:Program.cs

示例3: AStarSearch

    public void AStarSearch(Vector2 _Source, Vector2 _Target, bool _AllowUnwalkable)
    {
        m_SourceIndex = PointDatabase.Instance.GetIdealPoint(_Source,_Target).Index;
        m_TargetIndex = PointDatabase.Instance.GetClosestPointToPosition(_Target,_AllowUnwalkable).Index;

        List<Point> PointList = PointDatabase.Instance.ReturnDatabaseAsList();
        m_SearchFrontier = new Dictionary<string,Edge>();//store all points that are being searched
        m_ShortestPath = new Dictionary<string,Edge>();
        m_fCost = new Dictionary<string,float>();//cumulative cost to current node + heuristic cost from current node to target node
        m_gCost = new Dictionary<string,float>();//cumulative cost from the source node to the current node
        InitializeDictionaries();

        PriorityQueue priorityQueue = new PriorityQueue(m_fCost);
        priorityQueue.Add(m_SourceIndex);

        while(priorityQueue.Count() != 0)
        {
            string nextClosestPoint = priorityQueue.Dequeue();

            m_ShortestPath[nextClosestPoint] = m_SearchFrontier[nextClosestPoint];

            if(nextClosestPoint == m_TargetIndex)
            {
                return;
            }

            foreach(Edge edge in m_Database.Database[nextClosestPoint].Edges)
            {
                //heuristic cost from current node to target node
                float HCost = CalculateDistanceBetweenPoints(edge.End,m_Database.Database[m_TargetIndex]);
                //cumulative cost from the start node to the current node
                float GCost = m_gCost[nextClosestPoint] + edge.Cost;

                if(_AllowUnwalkable == false)
                {
                    if(m_SearchFrontier[edge.End.Index] == null && edge.End.Walkable == true)
                    {
                        m_fCost[edge.End.Index] = HCost + GCost;
                        m_gCost[edge.End.Index] = GCost;
                        priorityQueue.Add(edge.End.Index);
                        m_SearchFrontier[edge.End.Index] = edge;
                    }
                    else if(GCost < m_gCost[edge.End.Index] && m_ShortestPath[edge.End.Index] == null && edge.End.Walkable == true)
                    {
                        m_fCost[edge.End.Index] = HCost + GCost;
                        m_gCost[edge.End.Index] = GCost;
                        priorityQueue.Add(edge.End.Index);
                        m_SearchFrontier[edge.End.Index] = edge;
                    }
                }
                else
                {
                    if(m_SearchFrontier[edge.End.Index] == null)
                    {
                        m_fCost[edge.End.Index] = HCost + GCost;
                        m_gCost[edge.End.Index] = GCost;
                        priorityQueue.Add(edge.End.Index);
                        m_SearchFrontier[edge.End.Index] = edge;
                    }
                    else if(GCost < m_gCost[edge.End.Index] && m_ShortestPath[edge.End.Index] == null)
                    {
                        m_fCost[edge.End.Index] = HCost + GCost;
                        m_gCost[edge.End.Index] = GCost;
                        priorityQueue.Add(edge.End.Index);
                        m_SearchFrontier[edge.End.Index] = edge;
                    }
                }
            }
        }
    }
开发者ID:raynertanxw,项目名称:GDP_Cellulose,代码行数:70,代码来源:PathQuery.cs


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