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


C# LinkedList.Aggregate方法代码示例

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


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

示例1: Run

 public static void Run()
 {
     string[] line = Console.ReadLine().Split(' ');
     int n = Convert.ToInt32(line[0]), x1 = Convert.ToInt32(line[1]), y1 = Convert.ToInt32(line[2]),
         x2 = Convert.ToInt32(line[3]), y2 = Convert.ToInt32(line[4]);
     LinkedList<Flower> first = new LinkedList<Flower>();
     LinkedList<Flower> second = new LinkedList<Flower>();
     
     for (int i = 0; i < n; i++)
     {
         line = Console.ReadLine().Split(' ');
         int x = Convert.ToInt32(line[0]), y = Convert.ToInt32(line[1]);
         first.AddLast(new Flower { x = x, y = y, dist = (long)(x - x1) * (long)(x - x1) + (long)(y - y1) * (long)(y - y1) });
     }
     long res = long.MaxValue;
     for (int i = 0; i <= n; i++)
     {
         Flower firstmax = first.Count > 0 ? first.Aggregate((c, d) => c.dist > d.dist ? c : d) : null;
         Flower secondmax = second.Count > 0 ? second.Aggregate((c, d) => c.dist > d.dist ? c : d) : null;
         long d1 = 0, d2 = 0;
         if (firstmax != null) d1 = firstmax.dist;
         if (secondmax != null) d2 = secondmax.dist;
         res = Math.Min(res, d1 + d2);
         if (firstmax != null)
         {
             first.Remove(firstmax);
             firstmax.dist = (long)(firstmax.x - x2) * (long)(firstmax.x - x2) + (long)(firstmax.y - y2) * (long)(firstmax.y - y2);
             second.AddLast(firstmax);
         }
     }
     Console.WriteLine(res);
 }
开发者ID:dzholmukhanov,项目名称:AlgorithmTraining,代码行数:32,代码来源:WateringFlowers340.cs

示例2: Main

 static void Main(string[] args)
 {
     WordPrediction.Initialize();
     LinkedList<string> words = new LinkedList<string>();
     //if you like
     words.AddLast("for");
     words.AddLast("he");
     words.AddLast("was");
     foreach(var word in words)
     {
         Console.Write(word + " ");
     }
     while (true)
     {
         //var line = Console.ReadLine();
         var predictions = WordPrediction.Predict(words.Aggregate((a, b) => a + " " + b));
         predictions.OrderByDescending(a => a.Item2);
         words.RemoveFirst();
         var prediction = predictions.FirstOrDefault();
         if (prediction == null) break;
         var word = predictions.FirstOrDefault().Item1;
         words.AddLast(word);
         Console.Write(" " + word);
         Thread.Sleep(250);
     }
 }
开发者ID:bladespinner,项目名称:AI-Course-Project,代码行数:26,代码来源:Program.cs

示例3: ShowLines

 private static void ShowLines(LinkedList<IList<Int32>> storage)
 {
     // TODO (std_string) : need something such List.iter from F#
     storage.Aggregate(new Object(), (acc, columns) =>
     {
         ShowLine(columns);
         return acc;
     });
 }
开发者ID:stdstring,项目名称:hackerrank,代码行数:9,代码来源:Program.cs

示例4: BufferBody

        ResultDelegate BufferBody(IHttpResponseDelegate response)
        {
            return (status, headers, body) =>
            {
                var buffer = new LinkedList<ArraySegment<byte>>();

                body((data, continuation) =>
                {
                    var copy = new byte[data.Count];
                    Buffer.BlockCopy(data.Array, data.Offset, copy, 0, data.Count);
                    buffer.AddLast(new ArraySegment<byte>(copy));
                    return false;
                },
                HandleError(response),
                () =>
                {
                    var contentLength = buffer.Aggregate(0, (r, i) => r + i.Count);

                    IDataProducer responseBody = null;

                    if (contentLength > 0)
                    {
                        headers["Content-Length"] = contentLength.ToString();
                        responseBody = new DataProducer((onData, onError, onComplete) =>
                        {
                            bool cancelled = false;

                            while (!cancelled && buffer.Count > 0)
                            {
                                var next = buffer.First;
                                buffer.RemoveFirst();
                                onData(next.Value, null);
                            }

                            onComplete();

                            buffer = null;

                            return () => cancelled = true;
                        });
                    }

                    response.OnResponse(new HttpResponseHead()
                    {
                        Status = status,
                        Headers = headers
                    }, responseBody);
                });
            };
        }
开发者ID:bvanderveen,项目名称:gate,代码行数:50,代码来源:GateRequestDelegate.cs

示例5: CheckPermutations

        private long CheckPermutations(LinkedList<int> nodes, int[] a, int[] r, int level, long outerDiff)
        {
            long diff = long.MaxValue;
            int n = a.Length;
            var node = nodes.First;
            while (node != null)
            {
                if (node.Value == r[level])
                {
                    node = node.Next;
                    continue;
                }

                long nodeDiff = (node.Value - a[level]) * (long)Math.Pow(10, n - level - 1);
                if (diff != long.MaxValue && Math.Abs(outerDiff + nodeDiff) - Math.Abs(outerDiff + diff) >= (long)Math.Pow(10, n - level - 1))
                {
                    node = node.Next;
                    continue;
                }

                long childDiff = 0;
                if (nodes.Count > 1)
                {
                    var prevNode = node.Previous;
                    nodes.Remove(node);
                    long key = nodes.Aggregate(0L, (current, nd) => current * 10 + nd);

                    if (outerDiff + nodeDiff > 0)
                    {
                        if (!_diffsMin.TryGetValue(key, out childDiff))
                        {
                            childDiff = CheckPermutations(nodes, a, r, level + 1, outerDiff + nodeDiff);
                            _diffsMin[key] = childDiff;
                        }
                    }
                    else if (outerDiff + nodeDiff < 0)
                    {
                        if (!_diffsMax.TryGetValue(key, out childDiff))
                        {
                            childDiff = CheckPermutations(nodes, a, r, level + 1, outerDiff + nodeDiff);
                            _diffsMax[key] = childDiff;
                        }
                    }
                    else if(!_diffsAbsMin.TryGetValue(key, out childDiff))
                    {
                        childDiff = CheckPermutations(nodes, a, r, level + 1, outerDiff + nodeDiff);
                        _diffsAbsMin[key] = childDiff;
                    }

                    if (prevNode == null)
                        nodes.AddFirst(node);
                    else
                        nodes.AddAfter(prevNode, node);
                }

                if (childDiff == long.MaxValue)
                {
                    node = node.Next;
                    continue;
                }

                if (diff == long.MaxValue)
                    diff = nodeDiff + childDiff;
                else if (Math.Abs(outerDiff + nodeDiff + childDiff) < Math.Abs(outerDiff + diff))
                    diff = nodeDiff + childDiff;
                else if (Math.Abs(outerDiff + nodeDiff + childDiff) == Math.Abs(outerDiff + diff))
                    diff = Math.Min(nodeDiff + childDiff, diff);

                node = node.Next;
            }

            return diff;
        }
开发者ID:yuriysl,项目名称:Algorithms,代码行数:73,代码来源:KingdomAndPassword.cs

示例6: Run


//.........这里部分代码省略.........
								&& allSendersUp.CurrentCount < maxSenders)
							{
								senders.AddLast(endpoint);
								allSendersUp.Signal();
							}
						}
					});

				_logger.Info("waiting for all senders ...");
				allSendersUp.Wait();

				_logger.Info("sending 'ReadySetGo' to all senders");

				lock (senders)
					senders.Each(sender => sender.Send<ReadySetGo>(new {}));

				//unsubscribeMe = sb.SubscribeHandler<IConsumeContext<ZoomZoom>>(consumeContext =>
				unsubscribeMe += sb.SubscribeHandler<ZoomZoom>(payment =>
					{
						//var payment = consumeContext.Message;
						
						long currentReceived;
						if ((currentReceived = Interlocked.Increment(ref received)) == rampUp)
							watch.Start();
						else if (currentReceived < rampUp) return;

						var localFailures = new long?();
						if (Math.Abs(payment.Amount - 1024m) > 0.0001m)
						{
							localFailures = Interlocked.Increment(ref failures);
						}

						if (currentReceived + rampUp == sampleSize || _isStopping)
						{
							unsubscribeMe();
							watch.Stop();
							stopping.Set();
						}

						if (currentReceived % 100 == 0)
						{
							var point = new DataPoint
								{
									Received = currentReceived,
									Ticks = watch.ElapsedTicks,
									Failures = localFailures ?? failures,
									SampleMessage = payment,
									Instance = DateTime.UtcNow
									/* assume all prev 100 msgs same size */
									//Size = consumeContext.BaseContext.BodyStream.Length * 100 
								};
							lock (datapoints) datapoints.AddLast(point);
							_logger.Debug(string.Format("Logging {0}", point));
						}
					});

				PipelineViewer.Trace(sb.InboundPipeline);

				_logger.Info("waiting for all messages!");
				stopping.WaitOne();


				sb.GetEndpoint(creds.BuildUri("sender")).Send<ZoomDone>(new{});
			}

			_logger.Info(
string.Format(@"
Performance Test Done
=====================

Total messages received:  {0}
Time taken:               {1}

of which:
  Corrupt messages count: {2}
  Valid messages count:   {3}

metrics:
  Message per second:     {4}
  Total bytes transferred:{5}
  All samples' data equal:{6}

data points:
{7}
",
 sampleSize, watch.Elapsed, failures,
 sampleSize-failures,
 1000d * sampleSize / (double)watch.ElapsedMilliseconds,
 datapoints.Sum(dp => dp.Size),
 datapoints.Select(x => x.SampleMessage).All(x => x.Payload.Equals(TestData.PayloadMessage, StringComparison.InvariantCulture)),
 datapoints.Aggregate("", (str, dp) => str + dp.ToString() + Environment.NewLine)));

			_logger.Info("Idling... aka. softar.");
			
			while (true)
				Thread.Sleep(10000);

			// now have a look in Server Explorer, WADLogsTable, w/ Filter similar to "Timestamp gt datetime'2012-02-03T10:06:50Z'" 
			// (if this isn't your first deployment, or no filter if you feel like that)
		}
开发者ID:haf,项目名称:MassTransit-AzureServiceBus,代码行数:101,代码来源:ReceiverWorker.cs


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