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


C# SortedSet.ElementAt方法代码示例

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


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

示例1: OrdersAreSortedOnLastUpdateTimeIfPriceEqual

        public void OrdersAreSortedOnLastUpdateTimeIfPriceEqual(string order1,
                                                                string order2,
                                                                bool o1IsEarlier)
        {
            const int id1 = 1;
            const int id2 = 2;
            var earlyDate = new DateTime(2013, 01, 01, 10, 0, 0);
            var lateDate = new DateTime(2013, 01, 01, 10, 0, 1);
            var o1 = FakeOrder.CreateOrderFromString(id1, order1);
            var o2 = FakeOrder.CreateOrderFromString(id2, order2);
            o1.LastUpdateTime = o1IsEarlier ? earlyDate : lateDate;
            o2.LastUpdateTime = o1IsEarlier ? lateDate : earlyDate;
            Assert.AreEqual(o1.Price, o2.Price, "Orders must have same price for this test");

            var orders = new[] {o1, o2};
            var sorted = new SortedSet<IOrder>(orders, new OrderStack.StandardOrderComparer());
            Assert.AreEqual(2, sorted.Count, "Sorting has changed the number of orders!");
            if (o1IsEarlier)
            {
                Assert.AreEqual(id1, sorted.ElementAt(0).ID, "Order 1 should be first in the list");
                Assert.AreEqual(id2, sorted.ElementAt(1).ID, "Order 2 should be second in the list");
            }
            else
            {
                Assert.AreEqual(id2, sorted.ElementAt(0).ID, "Order 2 should be first in the list");
                Assert.AreEqual(id1, sorted.ElementAt(1).ID, "Order 1 should be second in the list");
            }
        }
开发者ID:naziway,项目名称:testtask,代码行数:28,代码来源:TestDefaultOrderSorter.cs

示例2: Execute

        public int Execute()
        {
            var fileItems = File.ReadAllLines(_file).Select(Int32.Parse).ToArray();
            var results = new List<int>();
            var manager = new SortedSet<int>();

            for (var i = 1; i <= fileItems.Length; i++)
            {
                var @value = fileItems[i-1];
                manager.Add(@value);

                if (i%2 == 0) results.Add(manager.ElementAt((i-1)/2));
                else results.Add(manager.ElementAt((i)/2));
            }

            return results.Sum() % 10000;
        }
开发者ID:RobertCPhillips,项目名称:CourseraAlgorithms,代码行数:17,代码来源:MedianMaint.cs

示例3: OrdersAreSortedByIDIfAllElseIsEqual

 public void OrdersAreSortedByIDIfAllElseIsEqual(string order1,
                                                 string order2)
 {
     const int id1 = 1;
     const int id2 = 2;
     var orders = new List<FakeOrder>
         {
             FakeOrder.CreateOrderFromString(id1, order1),
             FakeOrder.CreateOrderFromString(id2, order2)
         };
     var t = DateTime.UtcNow;
     orders.ForEach(o => o.LastUpdateTime = t);
     var sorted = new SortedSet<IOrder>(orders, new OrderStack.StandardOrderComparer());
     Assert.AreEqual(2, sorted.Count, "Sorting has changed the number of orders!");
     Assert.AreEqual(id1, sorted.ElementAt(0).ID, "Order 1 should be first in the list");
     Assert.AreEqual(id2, sorted.ElementAt(1).ID, "Order 2 should be second in the list");
 }
开发者ID:naziway,项目名称:testtask,代码行数:17,代码来源:TestDefaultOrderSorter.cs

示例4: Main

 static void Main()
 {
     string text = Console.ReadLine();
     SortedSet<char> sortedCharSet = new SortedSet<char> { };
     foreach (var ch in text)
     {
         sortedCharSet.Add(ch);
     }
     int counter = 0;
     for (int i = 0; i < sortedCharSet.Count; i++, counter=0)
     {
         for (int j = 0; j < text.Length; j++)
         {
             if (sortedCharSet.ElementAt(i) == text[j])
             {
                 counter++;
             }
         }
         Console.WriteLine("{0}: {1} time/s", sortedCharSet.ElementAt(i), counter);
     }
 }
开发者ID:k1r1L,项目名称:Soft-Uni-Homeworks,代码行数:21,代码来源:CountSymbols.cs

示例5: Main

 static void Main()
 {
     string text = Console.ReadLine();
     SortedSet<char> characters = new SortedSet<char>();
     for (int i = 0; i < text.Length; i++)
     {
         characters.Add(text[i]);
     }
     int[] counter = new int[characters.Count()];
     for (int i = 0; i < characters.Count; i++)
     {
         for (int j = 0; j < text.Length; j++)
         {
             if (text[j] == characters.ElementAt(i))
             {
                 counter[i]++;
             }
         }
     }
     for (int i = 0; i < characters.Count(); i++)
     {
         Console.WriteLine("{0}: {1} time/s", characters.ElementAt(i), counter[i]);
     }
 }
开发者ID:hristodobrev,项目名称:Software-University,代码行数:24,代码来源:CountSymbols.cs

示例6: CalculateMinDifference

    private static long CalculateMinDifference(SortedSet<long> numberCollection)
    {
        long difference = long.MaxValue;
        long previousNumber = numberCollection.ElementAt(0);
        foreach (long nextNumber in numberCollection)
        {
            if (nextNumber - previousNumber < difference && nextNumber != previousNumber)
            {
                difference = nextNumber - previousNumber;
            }

            previousNumber = nextNumber;
        }

        return difference;
    }
开发者ID:ROSSFilipov,项目名称:CSharp,代码行数:16,代码来源:GameOfBits.cs

示例7: GetPermutation

 public string GetPermutation(int n, int k) {
     --k;
     var factorial = Enumerable.Range(0, n).Select(i => Enumerable.Range(1, i).Aggregate(1, (agg, x) => agg * x)).ToArray();
     var numbers = new SortedSet<int>(Enumerable.Range(1, n));
     var sb = new StringBuilder();
     while (sb.Length < n)
     {
         var f = factorial[numbers.Count - 1];
         var index = k / f;
         var number = numbers.ElementAt(index);
         sb.Append(number);
         numbers.Remove(number);
         k %= f;
     }
     return sb.ToString();
 }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:16,代码来源:60.PermutationSequence.cs

示例8: OnProcess

            protected override void OnProcess(PixelRegion sourcePixelRegion, PixelRegion targetPixelRegion)
            {
                SortedSet<uint> array = new SortedSet<uint>();

                //int width = Convert.ToInt32(sourcePixelRegion.ImageSize.Width);

                targetPixelRegion.ForEachRow((index, width, position) =>
                {
                for (int i = 0; i < width; i++)
                {
                var pixel = index + i;
                array.Clear();
                //var pixel = Convert.ToInt32(index + position.X + i);

                var pixelCentral = GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel, 0);
                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - width - 1, pixelCentral));
                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - width, pixelCentral));
                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - width + 1, pixelCentral));

                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - 1, pixelCentral));
                array.Add(pixelCentral);
                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + 1, pixelCentral));

                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + width - 1, pixelCentral));
                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + width, pixelCentral));
                array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + width + 1, pixelCentral));

                targetPixelRegion.ImagePixels[pixel] = array.ElementAt((array.Count- 1) /2);//.OrderBy(it => it).ToList()[4];
                }
                });
                //for (; pixel<sourcePixelRegion.ImagePixels.Length-width-2; pixel++)
                //{

                //for (int i=0; i< targetPixelRegion.ImagePixels.Length-1; i++)
                //{

                //    //targetPixelRegion.ImagePixels[i];
                //    //targetPixelRegion.ForEachRow((index, width, position) =>
                //    //{

                //    //    //Parallel.For(0, width, (i) =>
                //    //    for (int i = 0; i < width; i++)
                //    //    {

                //    //array.Clear();
                //    ////var pixel = index + i;
                //    //array.Add(sourcePixelRegion.ImagePixels[pixel - width - 1]);
                //    //array.Add(sourcePixelRegion.ImagePixels[ pixel - width]);
                //    //array.Add(sourcePixelRegion.ImagePixels[ pixel - width + 1]);
                //    //array.Add(sourcePixelRegion.ImagePixels[ pixel - 1]);
                //    //array.Add(sourcePixelRegion.ImagePixels[ pixel]);
                //    //array.Add(sourcePixelRegion.ImagePixels[ pixel + 1]);
                //    //array.Add(sourcePixelRegion.ImagePixels[ pixel + width - 1]);
                //    //array.Add(sourcePixelRegion.ImagePixels[ pixel + width]);
                //    //array.Add(sourcePixelRegion.ImagePixels[pixel + width + 1]);

                //    targetPixelRegion.ImagePixels[pixel] = sourcePixelRegion.ImagePixels[pixel - 1];// GetPixelOrDefault(sourcePixelRegion, pixel);// array[4];
                //    }//  });
                    //for (int i = 0; i < width; ++i)
                    //{
                    //    //Almacenamos los pixels alrededor del actual en un array ordenado para coger la mediana
                    //    //var c = sourcePixelRegion.ImagePixels[index + i];
                    //    List<uint> array = new List<uint>();

                    //    var pixel = index + i;
                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - width - 1));
                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - width));
                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - width + 1));

                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - 1));
                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel));
                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + 1));

                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + width - 1));
                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + width));
                    //    array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + width + 1));

                    //    targetPixelRegion.ImagePixels[pixel] = array.OrderBy(it=>it).ToList()[4];
                    //}

                //});
            }
开发者ID:asiertarancon,项目名称:ImagingUWP,代码行数:82,代码来源:MedianFilter.cs

示例9: _DrawGraphWithCommodities

        /// <summary>
        /// This method takes graph file data for networkx graph and 
        /// creates vertexes, edges. It also creates random commodities with
        /// valid paths. 
        /// </summary>
        /// <param name="lines">graph file text</param>
        private void _DrawGraphWithCommodities(string [] lines)
        {
            int CommodityNum = this._NumberOfCommoditiesVal;
            int MinComm = this._MinimumDemandVal;
            int MaxComm = this._MaximumDemandVal + 1;
            int nodeID = 0;
            bool CommoditySet = false;
            List<int> Origins = new List<int>();
            List<int> Destinations = new List<int>();
            List<float> Demands = new List<float>();
            int OriginID = 0, DestID = 0;
            float demand = 0;
            SortedSet<int> nodeList = new SortedSet<int>();
             //   HashSet<int> nodeList = new HashSet<int>();
            HashSet<int> edgeOutNodes = new HashSet<int>();
            Random random = new Random();
            Dictionary<int, LinkedList<int>> EdgeMap = new Dictionary<int, LinkedList<int>>();

            Graph = new NetGraph(true);
            try
            {
                foreach (string line in lines) //create and add vertex to the graph
                {
                    string[] IDs = line.Split(' ');

                    if (int.TryParse(IDs[0], out nodeID))
                    {
                        foreach (string id in IDs)
                        {
                            int currID = int.Parse(id);
                            if (nodeList.Add(currID))
                            {
                               // _VList.Add(currID);
                                Graph.AddVertex(new NetVertex(currID));
                            }
                        }
                    }
                }
                for (int i = 0; i < nodeList.Count; i++)
                {
                    _VList.Add(nodeList.ElementAt(i));
                }
                this._IDCount = this._VList.Count();
                int from = 0, to = 0, curID = 0;
                int count = Graph.VertexCount;
                bool valid = true;
                //create edges, and keep record of vertex with edges going out for each valid vertex
                foreach (string line in lines)
                {
                    string[] IDs = line.Split(' ');

                    if (int.TryParse(IDs[0], out nodeID))
                    {
                        EdgeMap.Add(nodeID, new LinkedList<int>());
                        for (int j = 1; j < IDs.Length; j++)
                        {
                            curID = int.Parse(IDs[j]);
                            valid = true;
                            if(EdgeMap.ContainsKey(curID))
                            {
                                foreach (int id in EdgeMap[curID])
                                {
                                    if (id == nodeID) valid = false;
                                }
                            }
                            if (valid)
                            {
                                edgeOutNodes.Add(nodeID);
                                EdgeMap[nodeID].AddLast(curID);
                                for (int i = 0; i < count; i++)
                                {
                                    if (Graph.Vertices.ElementAt(i).ID == nodeID) from = i;
                                    if (Graph.Vertices.ElementAt(i).ID == curID) to = i;
                                }
                                this._AddNewGraphEdge(Graph.Vertices.ElementAt(from), Graph.Vertices.ElementAt(to));
                            }
                        }
                    }
                }

                //commodity is choosed at random, if that commodity does not already exist
                //check if it has valid path. if it exists then just add demand to it.

                for (int i = 0; i < _NumberOfCommoditiesVal; i++)
                {
                    CommoditySet = false;
                    while (!CommoditySet)
                    {
                        OriginID = random.Next(0, edgeOutNodes.Count);
                        OriginID = edgeOutNodes.ElementAt(OriginID);
                        DestID = random.Next(0, nodeList.Count);
                        DestID = nodeList.ElementAt(DestID);
                        demand = random.Next(MinComm, MaxComm);

//.........这里部分代码省略.........
开发者ID:RaminderKharaud,项目名称:NetworkSimulationApp,代码行数:101,代码来源:MainWindowViewModel.cs

示例10: TwoBidsAreSortedByDescendingPrice

 public void TwoBidsAreSortedByDescendingPrice(string b1, string b2, bool bid1Better)
 {
     // Note that quantity, last update time, ID don't come into it yet
     const int id1 = 1;
     const int id2 = 2;
     var bids = new[]
         {
             FakeOrder.CreateOrderFromString(id1, b1),
             FakeOrder.CreateOrderFromString(id2, b2)
         };
     var sorted = new SortedSet<IOrder>(bids, new OrderStack.StandardOrderComparer());
     Assert.AreEqual(2, sorted.Count, "Sorting has changed the number of orders!");
     if (bid1Better)
     {
         Assert.AreEqual(id1, sorted.ElementAt(0).ID, "Bid 1 should be first in the list");
         Assert.AreEqual(id2, sorted.ElementAt(1).ID, "Bid 2 should be second in the list");
     }
     else
     {
         Assert.AreEqual(id2, sorted.ElementAt(0).ID, "Bid 2 should be first in the list");
         Assert.AreEqual(id1, sorted.ElementAt(1).ID, "Bid 1 should be second in the list");
     }
 }
开发者ID:naziway,项目名称:testtask,代码行数:23,代码来源:TestDefaultOrderSorter.cs


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