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


C# Queue.Min方法代码示例

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


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

示例1: Main

    static void Main(string[] args)
    {
        Queue<int> queue = new Queue<int>();
        int[] commandArgs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        int add = commandArgs[0];
        int remove = commandArgs[1];
        int find = commandArgs[2];

        // Fill queue
        int[] queueInput = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        for (int i = 0; i < add; i++)
        {
            queue.Enqueue(queueInput[i]);
        }

        // Remove Dequeue
        for (int i = 0; i < remove; i++)
        {
            queue.Dequeue();
        }

        // Output
        if (queue.Contains(find))
        {
            Console.WriteLine("true");
        }
        else
        {
            Console.WriteLine(queue.Count > 0 ? queue.Min() : 0);
        }
    }
开发者ID:eMagicMan,项目名称:Study-CSharp,代码行数:32,代码来源:BasicQueueOperations.cs

示例2: CalculateAroon

        //Aroon
        public static void CalculateAroon(out string key, out string key2, StockPoints data, Dictionary<DateTime, Dictionary<string, double>> indicators, int period, out int offset)
        {
            key = string.Format("Aroon-UP({0})", period.ToString("00"));
            key2 = string.Format("Aroon-Down({0})", period.ToString("00"));
            offset = period - 1;

            // Aroon-Up = ((period - Days Since period-day High)/period) x 100
            double up;

            // Aroon-Down = ((period - Days Since period-day Low)/period) x 100
            double down;

            // day since 25 day high
            int high;

            // day since 25 day low
            int low;

            Queue<double> highVals = new Queue<double>();
            Queue<double> lowVals = new Queue<double>();

            int i = 0;
            foreach(StockPoint point in data)
            {
                highVals.Enqueue(point.High);
                lowVals.Enqueue(point.Low);
                if(highVals.Count > period)
                {
                    highVals.Dequeue();
                    lowVals.Dequeue();
                }

                if (i < period - 1)
                {
                    i++;
                }
                else
                {
                    high = period - highVals.ToList().IndexOf(highVals.Max());
                    low = period - highVals.ToList().IndexOf(highVals.Min());

                    up = ((period - high) / (double)period) * 100;
                    down = ((period - low) / (double)period) * 100;

                    AddValue(point.PointDateTime, key, up, indicators);
                    AddValue(point.PointDateTime, key2, down, indicators);
                }
            }
        }
开发者ID:Kushagratrivedi,项目名称:GitHub,代码行数:50,代码来源:IndicatorLib.cs

示例3: PrintResult

        private static void PrintResult(Queue<int> stackNumber, List<int> commands)
        {
            if (stackNumber.Count <= 0)
            {
                Console.WriteLine(0);
                return;
            }

            bool isContains = stackNumber.Contains(commands[2]);
            if (isContains)
            {
                Console.WriteLine("true");
            }
            else
            {
                int minValue = stackNumber.Min();
                Console.WriteLine(minValue);
            }
        }
开发者ID:IskraNikolova,项目名称:Advanced-CSharp,代码行数:19,代码来源:BasicQueueOperations.cs

示例4: Main

        public static void Main()
        {
            //read from line n1 = numbers to enqueue, n2 = numbers to dequeue, n3 = number to check if present
            int[] commandNumbers =
                Console.ReadLine()
                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(int.Parse)
                    .ToArray();

            int[] inputNumbers =
                Console.ReadLine()
                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(int.Parse)
                    .ToArray();

            Queue<int> numbers = new Queue<int>();

            for (int i = 0; i < commandNumbers[0]; i++)
            {
                numbers.Enqueue(inputNumbers[i]);
            }

            for (int i = 0; i < commandNumbers[1]; i++)
            {
                numbers.Dequeue();
            }

            if (numbers.Count == 0)
            {
                Console.WriteLine(0);
            }
            else if (numbers.Contains(commandNumbers[2]))
            {
                Console.WriteLine(true);
            }
            else
            {
                Console.WriteLine(numbers.Min());
            }
        }
开发者ID:Mario-Chaushki,项目名称:master,代码行数:40,代码来源:QueueOperations.cs

示例5: Main

        static void Main(string[] args)
        {
            int[] arguments = Console.ReadLine()
                .Split()
                .Select(int.Parse)
                .ToArray();
            int[] itemsForEnq = Console.ReadLine()
                .Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToArray();
            Queue<int> queue = new Queue<int>();
            for (int i = 0; i < arguments[0]; i++)
            {
                queue.Enqueue(itemsForEnq[i]);
            }
            for (int i = 0; i < arguments[1]; i++)
            {
                queue.Dequeue();
            }

            if (queue.Contains(arguments[2]))
            {
                Console.WriteLine("true");
            }
            else
            {
                if (queue.Count > 0)
                {
                    Console.WriteLine(queue.Min());
                }
                else
                {
                    Console.WriteLine(0);
                }
            }
        }
开发者ID:AlexanderKrustev,项目名称:SoftUni,代码行数:36,代码来源:BasicQueueOperations.cs

示例6: CalculateStochasticRSI

        // Stochastic RSI
        public static void CalculateStochasticRSI(out string key, StockPoints data, Dictionary<DateTime, Dictionary<string, double>> indicators, int period, out int offset, bool leverage = true)
        {
            key = string.Format("StocRSI({0})", period.ToString("00"));
            ExponentialMovingAverage gains = new ExponentialMovingAverage(period);
            ExponentialMovingAverage losses = new ExponentialMovingAverage(period);
            offset = period * 2;

            double rsi;
            double stochRSI;
            double highestRSI;
            double lowestRSI;

            Queue<double> rsiQueue = new Queue<double>();

            StockPoint previousPoint = data[0];
            int i = 0;
            foreach (StockPoint point in data.Skip(1))
            {
                if (previousPoint.Close > point.Close)
                {
                    losses.AddValue(previousPoint.Close - point.Close);
                    gains.AddValue(0);
                }
                else if (previousPoint.Close < point.Close)
                {
                    gains.AddValue(point.Close - previousPoint.Close);
                    losses.AddValue(0);
                }

                if (i < period - 1)
                {
                    i++;
                }
                else
                {
                    rsi = 100 - (100 / (1 + (gains.MovingAverage / losses.MovingAverage)));

                    rsiQueue.Enqueue(rsi);
                    if (rsiQueue.Count > period)
                    {
                        rsiQueue.Dequeue();
                    }

                    if (rsiQueue.Count == period)
                    {
                        highestRSI = rsiQueue.Max();
                        lowestRSI = rsiQueue.Min();

                        stochRSI = (rsi - lowestRSI) / (highestRSI - lowestRSI) * (leverage ? 100 : 1);

                        AddValue(point.PointDateTime, key, stochRSI, indicators);
                    }
                }

                previousPoint = point;
            }
        }
开发者ID:Kushagratrivedi,项目名称:GitHub,代码行数:58,代码来源:IndicatorLib.cs

示例7: QueueExtensions_Min_ThrowsExceptionIfQueueIsEmpty

        public void QueueExtensions_Min_ThrowsExceptionIfQueueIsEmpty()
        {
            var queue = new Queue<Int32>();

            Assert.That(() => queue.Min(),
                Throws.TypeOf<InvalidOperationException>());
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:7,代码来源:QueueExtensionsTest.cs

示例8: QueueExtensions_Min_ReturnsMinValue

        public void QueueExtensions_Min_ReturnsMinValue()
        {
            var queue = new Queue<Int32>();
            queue.Enqueue(4);
            queue.Enqueue(5);
            queue.Enqueue(6);
            queue.Enqueue(99);
            queue.Enqueue(10);
            queue.Enqueue(1);
            queue.Enqueue(12);
            queue.Enqueue(45);

            var result = queue.Min();

            TheResultingValue(result).ShouldBe(1);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:16,代码来源:QueueExtensionsTest.cs

示例9: QueueExtensions_Min_ThrowsExceptionIfQueueIsEmpty

        public void QueueExtensions_Min_ThrowsExceptionIfQueueIsEmpty()
        {
            var queue = new Queue<Int32>();

            queue.Min();
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:6,代码来源:QueueExtensionsTest.cs


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