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


C# Queue.OrderBy方法代码示例

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


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

示例1: Step

        public bool Step()
        {
            // Check battle end conditions
            if (checkEnd()) {
                Ended(this, EventArgs.Empty);
                return false;
            }

            // Fill the turn queue and sort it by speed
            if (turnQueue.Count() == 0) {
                if (fighters.Count() == 0) {
                    return true;
                }

                turnQueue = new Queue<Fighter>(fighters);
                turnQueue.OrderBy(fighter => fighter.Stats.Speed);
            }

            // Assign first fighter
            if (currentFighter == null) {
                currentFighter = turnQueue.Dequeue();
                currentFighter.PreStep();
            } else if (!currentFighter.IsAlive() || currentFighter.Step(this)) {
                currentFighter = null;
            }

            return false;
        }
开发者ID:RolandMQuiros,项目名称:LostGenerationOld,代码行数:28,代码来源:Battle.cs

示例2: PrePareIncomingWater

    /// <summary>
    /// Mixes the incoming water and sorts it in queue according to time
    /// </summary>
    private void PrePareIncomingWater()
    {
      double ControlVolume = Incoming.Sum(var => var.Third.Volume);
      Queue<DateTime> Starts = new Queue<DateTime>();
      Queue<DateTime> Ends = new Queue<DateTime>();

      List<Tuple<DateTime, DateTime>> TimeSpans = new List<Tuple<DateTime, DateTime>>();

      foreach (DateTime D in Incoming.Select(var => var.First).OrderBy(var => var).Distinct())
        Starts.Enqueue(D);

      foreach (DateTime D in Incoming.Select(var => var.Second).OrderBy(var => var).Distinct())
        Ends.Enqueue(D);

      while (Starts.Count > 0 & Ends.Count>0)
      {
        DateTime d = Starts.Dequeue();

        if (Starts.Count > 0)
        {
          if (Starts.Peek() < Ends.Peek())
            TimeSpans.Add(new Tuple<DateTime, DateTime>(d, Starts.Peek()));
          else
          {
            DateTime e = Ends.Dequeue();
            TimeSpans.Add(new Tuple<DateTime, DateTime>(d, e));
            Starts.Enqueue(e);
            var p = Starts.OrderBy(var => var).ToList();
            Starts.Clear();
            foreach (DateTime D in p)
              Starts.Enqueue(D);
          }
        }
        else
        {
          DateTime e = Ends.Dequeue();
          TimeSpans.Add(new Tuple<DateTime, DateTime>(d, e));
          Starts.Enqueue(e);
        }
      }

      //Store the volumes before substracting anything
      Dictionary<IWaterPacket,double> _vols = new Dictionary<IWaterPacket,double>();
      foreach(var i in Incoming)
      {
        _vols.Add(i.Third,i.Third.Volume);
      }

      foreach (var v in TimeSpans)
      {
        var l = Incoming.Where(var => var.First < v.Item2 & var.Second > v.Item1).ToList();

        if(l.Count>0)
        {
          double d = v.Item2.Subtract(v.Item1).TotalSeconds;
          IWaterPacket wp = l[0].Third.Substract(d /(l[0].Second.Subtract(l[0].First).TotalSeconds) * _vols[l[0].Third]);
          for (int i = 1; i < l.Count; i++)
          {
            wp.Add(l[i].Third.Substract( d /(l[i].Second.Subtract(l[i].First).TotalSeconds) * _vols[l[i].Third]));
          }
          _incomingWater.Enqueue(wp);
        }
      }

      //Check the mass balance
      if (_incomingWater.Sum(var=> var.Volume) - ControlVolume > 1E-4)
        throw new Exception("Error in algorithm to mix incoming water");

      Incoming.Clear();
    }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:73,代码来源:Stream.cs

示例3: splitBoxes

        /**
         * Iterate through the {@link java.util.Queue}, popping
         * {@link ColorCutQuantizer.Vbox} objects from the queue
         * and splitting them. Once split, the new box and the remaining box are offered back to the
         * queue.
         *
         * @param queue {@link java.util.PriorityQueue} to poll for boxes
         * @param maxSize Maximum amount of boxes to split
         */
        private Queue<Vbox> splitBoxes(Queue<Vbox> queue, int maxSize)
        {
            while (queue.Count < maxSize)
            {
                queue = new Queue<Vbox>(queue.OrderByDescending(v => v.getVolume()));
                Vbox vbox = queue.Dequeue();

                if (vbox != null && vbox.canSplit())
                {
                    // First split the box, and offer the result
                    queue.Enqueue(vbox.splitBox());
                    // Then offer the box back
                    queue.Enqueue(vbox);
                }
                else
                {
                    break;
                }
            }

            queue = new Queue<Vbox>(queue.OrderBy(v => v.getVolume()));
            return queue;
        }
开发者ID:renewal-wu,项目名称:PaletteSample,代码行数:32,代码来源:ColorCutQuantizer.cs


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