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


C# PriorityQueue.Count方法代码示例

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


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

示例1: WorkPriorityQueue

 public void WorkPriorityQueue()
 {
     Student firstStudent = new Student("Alina", "Kylish", 123456789, new DateTime(1988, 4, 3));
     Student secondStudent = new Student("Elena", "Kylish", 987654321, new DateTime(1987, 8, 15));
     Student thirdStudent = new Student("Oleg", "Ivanov", 975312468, new DateTime(1992, 11, 20));
     Student fourthStudent = new Student("Andrey", "Pavlov", 1243576890, new DateTime(1977, 8, 10));
     PriorityQueue<Student> students = new PriorityQueue<Student>();
     students.Enqueue(firstStudent, 0);
     students.Enqueue(secondStudent, 1);
     students.Enqueue(thirdStudent, 2);
     students.Enqueue(fourthStudent, 0);
     Console.WriteLine(students.Count());
     Console.WriteLine(students.First());
     Console.WriteLine(students.Last());
     students.Dequeue();
     Console.WriteLine(students.Count());
     Console.ReadKey();
     students.Clear();
     students.Dequeue(); // throw exeption with message "Queue is empty. There is no value in queue"
 }
开发者ID:vbre,项目名称:tasks_cs2,代码行数:20,代码来源:EncapsulationExercises.cs

示例2: WorkWithPriorityQueue

        static void WorkWithPriorityQueue()
        {
            PriorityQueue<int> numbers = new PriorityQueue<int>();
            try
            {
                Console.WriteLine("Count = {0}", numbers.Count());
                //Console.WriteLine(numbers.First());
                //Console.WriteLine(numbers.Last());
                //numbers.Add(10);
               // Print(numbers);
                numbers.Enqueue(1, 5);
                numbers.Enqueue(2, 11);
                numbers.Enqueue(1, 1);
               // Print(numbers);
                numbers.Enqueue(2, 1);
                numbers.Enqueue(3, 1);
                numbers.Enqueue(15, 2);
                numbers.Enqueue(25, 2);
                numbers.Enqueue(21, 2);
              //  Print(numbers);
                numbers.Enqueue(1021, 3);
                numbers.Enqueue(375, 5);
                numbers.Enqueue(124243323, 8);
              //  Print(numbers);
                Console.WriteLine("Count = {0}", numbers.Count());
                Console.WriteLine("Count with priority 1= {0}", numbers.GetCount(1));
                Console.WriteLine("Count with priority 2= {0}", numbers.GetCount(2));
                Console.WriteLine("Count with priority 3= {0}", numbers.GetCount(3));
                Console.WriteLine("Count with priority 4= {0}", numbers.GetCount(4));
                Console.WriteLine("Count with priority 5= {0}", numbers.GetCount(5));
                Console.WriteLine("Count with priority 8= {0}", numbers.GetCount(8));
                Console.WriteLine("Count with priority 11= {0}", numbers.GetCount(11));
                Console.WriteLine(numbers.First());
                Console.WriteLine(numbers.Last());
                Console.WriteLine(numbers.Dequeue());
             //   Print(numbers);
                Console.WriteLine(numbers.Dequeue());
                Console.WriteLine(numbers.Dequeue());
                Console.WriteLine(numbers.Dequeue());
              //  Print(numbers);
                Console.WriteLine(numbers.Dequeue());
                Console.WriteLine(numbers.Dequeue());
                Console.WriteLine(numbers.Dequeue());
             //   Print(numbers);
                Console.WriteLine("Count = {0}", numbers.Count());
                Console.WriteLine("Count with priority 1= {0}", numbers.GetCount(1));
                Console.WriteLine("Count with priority 2= {0}", numbers.GetCount(2));
                Console.WriteLine("Count with priority 3= {0}", numbers.GetCount(3));
                Console.WriteLine("Count with priority 4= {0}", numbers.GetCount(4));
                Console.WriteLine("Count with priority 5= {0}", numbers.GetCount(5));
                Console.WriteLine("Count with priority 8= {0}", numbers.GetCount(8));
                Console.WriteLine("Count with priority 11= {0}", numbers.GetCount(11));
                numbers.Clear();
                Console.WriteLine("Count = {0}", numbers.Count<int>());
             //   Print(numbers);

                numbers.Add(10);
                numbers.Add(11);
                Console.WriteLine(numbers.First());
                Console.WriteLine(numbers.Last());
                Console.WriteLine();
                numbers.Enqueue(1, 5);
                numbers.Add(5);
                Print(numbers);
                Console.WriteLine();
            }
            catch
            {
                Console.WriteLine("Is Exeption");
            }
            Console.ReadKey();
        }
开发者ID:Mechtatel-student,项目名称:tasks_cs1,代码行数:72,代码来源:CollectionsExercises.cs

示例3: FindPath

        public static List<Position> FindPath( Engine engine, Unit unit, Tile start, Tile end )
        {
            List<Position> path = null;

            if (!unit.CanMove(end.position))
            {
                foreach (Position pos in BreadthFirst(engine, end.position, -1, 500))
                {
                    if (unit.CanMove(pos))
                    {
                        end = engine.map.tiles[pos.x, pos.y];
                        break;
                    }
                }
            }
            if (!unit.CanMove(end.position))
            {
                return null;
            }

            bool success = false;
            start.pathParent = null;
            start.pathDistance = 0;
            start.pathHeuristic = start.pathDistance + FValue(start, end);
            PriorityQueue<Tile> openSet = new PriorityQueue<Tile>();
            openSet.Enqueue(start);
            int count = 0;

            //generate path
            while ( openSet.Count() > 0 )
            {
                count += 1;
                Tile currentBest = openSet.Dequeue();
                currentBest.pathIndex = pathCounter;
                // if we are at the goal end
                if (currentBest.position.Equals(end.position))
                {
                    success = true;
                    break;
                }
                // Give up if we backtrack too far
                if ((currentBest.pathHeuristic >= start.pathHeuristic*14 &&
                    count > 2000) || count > 4000)
                {
                    break;
                }
                // Take current best, generate all possible nodes, push them onto queue
                foreach (var neighbor in currentBest.neighbors)
                {
                    if (!unit.CanMove(neighbor.position))
                    {
                        continue;
                    }
                    double tentativeCost = currentBest.pathDistance + neighbor.tileType.movementCost;
                    if (neighbor.pathIndex < pathCounter)
                    {
                        neighbor.pathIndex = pathCounter;
                        neighbor.pathParent = currentBest;
                        neighbor.pathDistance = tentativeCost;
                        neighbor.pathHeuristic = neighbor.pathDistance + FValue(neighbor, end);
                        openSet.Enqueue(neighbor);
                    }
                    else if (tentativeCost < neighbor.pathDistance)
                    {
                        // Update costs if the current path is better than the existing one
                        neighbor.pathParent = currentBest;
                        neighbor.pathDistance = tentativeCost;
                        neighbor.pathHeuristic = neighbor.pathDistance + FValue(neighbor, end);
                        openSet.HeapifyUp(neighbor);
                    }
                }
            }
            if ( success )
            {
                // Generate path by following parent from end to start
                path = new List<Position>();
                Tile runner = end;
                while (runner != null)
                {
                    path.Insert(0, runner.position);
                    runner = runner.pathParent;
                }
            }

            pathCounter += 1;

            return path;
        }
开发者ID:XNAWizards,项目名称:mst-boredom-remover,代码行数:88,代码来源:Pathfinder.cs

示例4: Count_length_of_non_empty_queue

 public void Count_length_of_non_empty_queue()
 {
     var sut = new PriorityQueue<string>();
     sut.Enqueue("a", 1);
     Assert.AreEqual(1, sut.Count());
 }
开发者ID:ralfw,项目名称:TDDaiymiByExample,代码行数:6,代码来源:test_PriorityQueue.cs

示例5: Count_length_of_empty_queue

 public void Count_length_of_empty_queue()
 {
     var sut = new PriorityQueue<string>();
     Assert.AreEqual(0, sut.Count());
 }
开发者ID:ralfw,项目名称:TDDaiymiByExample,代码行数:5,代码来源:test_PriorityQueue.cs

示例6: findRouteD

        //    Finds the next node to hop to in the route to vertDestination and returns it's handler
        //    if all neighbour nodes are overloaded, than return the source node
        private List<Vertex> findRouteD( int hndlSource, int hndlDestination )
        {
            int numNodes = this.xDim * this.yDim;
            PriorityQueue<int, int> minRouteQ = new PriorityQueue<int, int>( numNodes );
            List<Vertex> pathList = new List<Vertex>( numNodes - 1 );

            //	marking all vertices with infinite distance
            foreach ( Vertex vrt in this.vertexList.TheList )
            {
                minRouteQ.AddToBottom( int.MaxValue, vrt.Handler );
            }

            //	assigning the source vertex 0 distance value
            minRouteQ.SetPriority( hndlSource, 0 );

            int currentHandler = 0;
            int minDistance;

            //	going through all vertices
            while ( minRouteQ.Count() != 0 )
            {
                //	checking what's on top of the priority queue
                minDistance = minRouteQ.PeekTop().Priority;
                currentHandler = minRouteQ.PeekTop().Data;

                //	removing the current element from the queue
                minRouteQ.Dequeue();

                //	all remaining vertices are inaccesible from source
                if ( minDistance == int.MaxValue )
                {
                    break;
                }

                List<int> currentNeightBours = this.incidencyMatrix.GetConnectedVertices( currentHandler );
                int distFromCurrent;

                foreach ( int vHandler in currentNeightBours )
                {
                    distFromCurrent = this.incidencyMatrix.GetDistance( currentHandler, vHandler ) + minDistance;

                    if ( minRouteQ.GetPriority(vHandler) > distFromCurrent )
                    {
                        minRouteQ.SetPriority( vHandler, distFromCurrent );
                        pathList.Add( this.vertexList.Find(vHandler) );
                    }
                }
            }

            //minRouteQ
            return pathList;
        }
开发者ID:dodev,项目名称:LatticeNetworkSimulator,代码行数:54,代码来源:Network.cs


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