[英]How to find the minimum and maximum element from queue?
I am making application using c#. 我正在使用c#进行应用程序。 I have one queue as follows... 我有一个队列如下...
Queue QueueData = new Queue(60);
I want to find the min and max element from that queue. 我想从该队列中找到最小和最大元素。 Any ideas? 有任何想法吗?
You could use linq Min
and Max
methods. 您可以使用linq的Min
和Max
方法。
Convert your Queue
to Queue<T>
and look here for examples: http://code.msdn.microsoft.com/LINQ-Aggregate-Operators-c51b3869 将您的Queue
转换为Queue<T>
并在此处查看示例: http : //code.msdn.microsoft.com/LINQ-Aggregate-Operators-c51b3869
Of course, you must specify what value you want the max and min values of: 当然,您必须指定所需的最大值和最小值:
var max = QueueData.Max(x => x.SomeSelectedComparableValue);
var min = QueueData.Min(x => x.SomeSelectedComparableValue);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.