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


C# PriorityQueue.GetCount方法代码示例

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


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

示例1: WorkPriorityQueue

        public void WorkPriorityQueue()
        {
            var intPriorityQueue = new PriorityQueue<int>();
            var stringPriorityQueue = new PriorityQueue<string>();
            var userPriorityQueue = new PriorityQueue<User>();

            try
            {
                intPriorityQueue.Enqueue(5, 1);
                intPriorityQueue.Enqueue(40, 1);
                Console.WriteLine("Number of elements of 1st order in queue = {0}", intPriorityQueue.GetCount(1));
                Console.WriteLine("First element of 1st priority = {0}", intPriorityQueue.First());
                Console.WriteLine("Last element of 1st priority = {0}", intPriorityQueue.Last());
                intPriorityQueue.Dequeue();
                intPriorityQueue.Enqueue(671, 2);
                intPriorityQueue.Enqueue(30, 4);
                intPriorityQueue.Enqueue(8932, 4);
                Console.WriteLine("First element of 4th priority = {0}", intPriorityQueue.First(4));
                Console.WriteLine("Last element of 4th priority = {0}", intPriorityQueue.Last(4));
                Console.WriteLine("Queue length = {0}", intPriorityQueue.Count);

                stringPriorityQueue.Enqueue("", 7);
                stringPriorityQueue.Enqueue("40", 7);
                //Console.WriteLine("Number of elements of 1st order in queue = {0}", stringPriorityQueue.GetCount(1));
                Console.WriteLine("First element of 1st priority = {0}", stringPriorityQueue.First());
                Console.WriteLine("Last element of 1st priority = {0}", stringPriorityQueue.Last());
                stringPriorityQueue.Dequeue();
                stringPriorityQueue.Enqueue("thirteen", 4);
                stringPriorityQueue.Enqueue("god", 4);
                Console.WriteLine("First element of 4th priority = {0}", stringPriorityQueue.First(4));
                Console.WriteLine("Last element of 4th priority = {0}", stringPriorityQueue.Last(4));
                Console.WriteLine("Queue length = {0}", stringPriorityQueue.Count);

                userPriorityQueue.Enqueue(new User("Bardara", "Morgrad", new DateTime(1992, 12, 5)), 1);
                userPriorityQueue.Enqueue(new User("Viki", "Crachkovic", new DateTime(1982, 2, 5)), 2);
                Console.WriteLine("Number of elements of 1st order in queue = {0}", userPriorityQueue.GetCount(1));
                Console.WriteLine("First element of 1st priority = {0}", userPriorityQueue.First().FullName);
                Console.WriteLine("Last element of 1st priority = {0}", userPriorityQueue.Last().FullName);
                userPriorityQueue.Dequeue();
                userPriorityQueue.Enqueue(new User("Somalien", "Fred", new DateTime(1976, 12, 5)), 2);
                //Console.WriteLine("First element of 4th priority = {0}", userPriorityQueue.First(4).FullName);
                //Console.WriteLine("Last element of 4th priority = {0}", userPriorityQueue.Last(4).FullName);
                Console.WriteLine("Queue length = {0}", userPriorityQueue.Count);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occured - {0}", e.Message);
            }
            Console.ReadKey();
        }
开发者ID:imnikoo,项目名称:tasks_cs1,代码行数:50,代码来源:CollectionsExercises.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: WorkPriorityQueue

        public void WorkPriorityQueue()
        {
            //throw new NotImplementedException();
            PriorityQueue<int> testQueue = new PriorityQueue<int>();
            testQueue.Enqueue(1, 0);
            testQueue.Enqueue(2, 0);
            testQueue.Enqueue(3, 0);
            testQueue.Enqueue(4, 0);
            testQueue.Enqueue(5, 0);

            testQueue.Enqueue(1, 2);
            testQueue.Enqueue(2, 2);
            testQueue.Enqueue(3, 3);
            testQueue.Enqueue(4, 3);
            testQueue.Enqueue(5, 5);

            Console.WriteLine();
            Console.WriteLine("First test {0}", testQueue.First());  // 1
            Console.WriteLine("Last test {0}", testQueue.Last());    // 5

            Console.WriteLine("First test {0} с приоритетом {1}", testQueue.First(2), 2);  //1
            Console.WriteLine("Last test {0} с приоритетом {1}", testQueue.Last(3), 3);    // 4

            int p1 = 0;
            Console.WriteLine("число элементов с приоритетом {0} = {1}", p1, testQueue.GetCount(p1));  //5
            p1 = 2;
            Console.WriteLine("число элементов с приоритетом {0} = {1}", p1, testQueue.GetCount(p1));  //2
            p1 = 5;
            Console.WriteLine("число элементов с приоритетом {0} = {1}", p1, testQueue.GetCount(p1));  //1

            Console.ReadKey();
        }
开发者ID:vbre,项目名称:tasks_cs2,代码行数:32,代码来源:EncapsulationExercises.cs

示例4: WorkPriorityQueue

        public void WorkPriorityQueue()
        {
            PriorityQueue<string> q1 = new PriorityQueue<string>();
            PriorityQueue<int> q2 = new PriorityQueue<int>();
            PriorityQueue<Group> q3 = new PriorityQueue<Group>();

            q1.Enqueue(new List<string> { "A", "B", "C" }, 5);
            q1.Enqueue(new List<string> { "F", "G", "H" }, 1);
            q1.Enqueue(new List<string> { "X", "V", "B" }, 0);
            q1.Enqueue(new List<string> { "Q", "W", "E" }, 1);
            q1.Enqueue("Z", 1);

            q2.Enqueue(new List<int> { 4, 5, 6 }, 5);
            q2.Enqueue(new List<int> { 1, 2, 3 }, 1);
            q2.Enqueue(new List<int> { 7, 8, 9 }, 0);
            q2.Enqueue(new List<int> { 0, 3, 5 }, 1);
            q2.Enqueue(9, 2);

            q3.Enqueue(new Group("CS1", 7), 1);
            q3.Enqueue(new Group("CS2", 14), 3);
            q3.Enqueue(new Group("CS3", 24), 5);
            q3.Enqueue(new Group("CS4", 31), 1);

            Console.WriteLine("Dequeue in Q1: " + q1.Dequeue());
            Console.WriteLine("First in Q1: " + q1.First());
            Console.WriteLine("First with priority = 1 in Q1: " + q1.First(1));
            Console.WriteLine("Last in Q1: " + q1.Last());
            Console.WriteLine("Last with priority = 1 in Q1: " + q1.Last(1));
            Console.WriteLine("Count in Q1: " + q1.Count);
            Console.WriteLine("Count with priority = 1 in Q1: " + q1.GetCount(1));

            Console.WriteLine("__________________________________________________");

            Console.WriteLine("Dequeue in Q2: " + q2.Dequeue());
            Console.WriteLine("First in Q2: " + q2.First());
            Console.WriteLine("First with priority = 1 in Q2: " + q2.First(1));
            Console.WriteLine("Last in Q2: " + q2.Last());
            Console.WriteLine("Last with priority = 1 in Q2: " + q2.Last(1));
            Console.WriteLine("Count in Q2: " + q2.Count);
            Console.WriteLine("Count with priority = 1 in Q2: " + q2.GetCount(1));

            Console.WriteLine("__________________________________________________");

            Console.WriteLine("Dequeue in Q3: " + q3.Dequeue().Title);
            Console.WriteLine("First in Q3: " + q3.First().Title);
            Console.WriteLine("First with priority = 1 in Q3: " + q3.First(1).Title);
            Console.WriteLine("Last in Q3: " + q3.Last().Title);
            Console.WriteLine("Last with priority = 1 in Q3: " + q3.Last(1).Title);
            Console.WriteLine("Count in Q3: " + q3.Count);
            Console.WriteLine("Count with priority = 1 in Q3: " + q3.GetCount(1));

            Console.WriteLine("__________________________________________________");
            bool q = q1.Contains(new Tuple<string, int>("7", 1));
            Console.WriteLine("Contains('7', 1) in Q1: " + q);
            q = q1.Contains(new Tuple<string, int>("Z", 1));
            Console.WriteLine("Contains('Z', 1) in Q1: " + q);

            q2.Clear();
            Console.WriteLine("Clear in Q2: " + q2.Count);

            Tuple<string, int>[] array = new Tuple<string, int>[15];

            q1.CopyTo(array, 0);

            for (int i = 0; i < array.Length; i++)
            {
                Console.WriteLine("Array[{0}] = ( {1}  {2})", i, array[i].Item2, array[i].Item1);
            }

            Console.ReadLine();
        }
开发者ID:SalamanderSunburn,项目名称:tasks_cs1,代码行数:71,代码来源:CollectionsExercises.cs


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