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


C# Queue.First方法代码示例

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


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

示例1: produce

        public static FunctionCall produce(Queue<Token> tokens)
        {
            // function_call = function_name "(" [ argument_list ] ")" terminator ;

            Token first = tokens.First();

            while (first.tokenType != TokenType.IDENTIFIER)
            {
                tokens.Dequeue();
                first = tokens.First();
            }

            Identifier functionName = IdentifierFactory.produce(tokens);
            tokens.Dequeue();

            // "("
            expect(tokens, TokenType.OPENPARENTHESE);

            // [ argument_list ]
            ArgumentList argumentList = null;
            if (tokens.First().tokenType != TokenType.CLOSEPARENTHESE)
            {
                argumentList = ArgumentListFactory.produce(tokens);
            }

            // ")"
            expect(tokens, TokenType.CLOSEPARENTHESE);

            // terminator
            optionalTerminator(tokens);

            return argumentList == null ? new FunctionCall(functionName) : new FunctionCall(functionName, argumentList);
        }
开发者ID:galderli,项目名称:dp2compiler,代码行数:33,代码来源:FunctionCallFactory.cs

示例2: PrintSequence

        public static void PrintSequence(int n)
        {
            var sequence = new Queue<int>();

            sequence.Enqueue(n);
            for (int i = 0; i < firstNNumbers; i++)
            {
                sequence.Enqueue(sequence.First() + 1);
                sequence.Enqueue(sequence.First() * 2 + 1);
                sequence.Enqueue(sequence.First() + 2);
                Console.WriteLine(sequence.Dequeue());
            }
        }
开发者ID:NikitoG,项目名称:TelerikAcademyHomeworks,代码行数:13,代码来源:Startup.cs

示例3: Main

        public static void Main()
        {
            Queue<int> quene = new Queue<int>();
            int n = 2;
            quene.Enqueue(n);

            for (int i = 0; i < 50; i++)
            {
                quene.Enqueue(quene.First() + 1);
                quene.Enqueue(2 * quene.First() + 1);
                quene.Enqueue(quene.First() + 2);
                Console.Write(quene.Dequeue()+ ", ");
            }
        }
开发者ID:dchakov,项目名称:Data-Structures-and-Algorithms_HW,代码行数:14,代码来源:Startup.cs

示例4: Main

        static void Main(string[] args)
        {
            var loops = 50;
            int startNumber = 2;
            Queue<int> sequenceConstructor = new Queue<int>();

            sequenceConstructor.Enqueue(startNumber);
            for (int i = 0; i < loops; i++)
            {
                sequenceConstructor.Enqueue(sequenceConstructor.First()+1);
                sequenceConstructor.Enqueue(sequenceConstructor.First() * 2 + 1);
                sequenceConstructor.Enqueue(sequenceConstructor.First() + 2);
                Console.WriteLine(sequenceConstructor.Dequeue());
            }
        }
开发者ID:AYankova,项目名称:Telerik-Academy-HW,代码行数:15,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            var gameGrid = new GameGrid();
            var printer = new GameGridPrinter();
            var rules = new GameRules();

            // Todo, get the number of human players from console
            // 3d TicTacToe using some web graphics thing???
            IPlayer player1 = new ConsoleHumanPlayer("Player 1", GridValue.X);
            IPlayer player2 = new MiniMaxPlayer("Player 2", GridValue.O, rules);
            var playerQueue = new Queue<IPlayer>(new[] { player1, player2 });

            while (true)
            {
                printer.Print(gameGrid);

                var player = playerQueue.Dequeue();
                playerQueue.Enqueue(player);

                var move = player.GetMove(gameGrid);
                gameGrid.PlaceMove(move);
                var winner = rules.GetWinner(gameGrid);
                if(winner == null)
                {
                    continue;
                }

                printer.PrintWinner(playerQueue.First(x => x.PlayerSide == winner), gameGrid);
                break;
            }

            // Todo, abstract
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
开发者ID:SlowShip,项目名称:AI,代码行数:35,代码来源:Program.cs

示例6: EnqueueOne

 public void EnqueueOne()
 {
     var queue = new Queue<string>();
     queue.Enqueue("foo");
     var item = queue.First();
     AssertEquals(item, "foo");
 }
开发者ID:x335,项目名称:WootzJs,代码行数:7,代码来源:QueueTests.cs

示例7: Auth

        public static void Auth(Queue<string> parameters)
        {
            var url = VimeoHook.GetLoginURL(
                clientId: Constants.GetVimeoAPIKey(),
                redirect: Constants.GetVimeoRedirectURL());
            App.Info("Open this URL and follow the instructions:");
            App.Info(url);
            if (parameters.Count > 0 && parameters.First().ToLower() == "ie")
            {
                parameters.Dequeue();
                var psi = new ProcessStartInfo("iexplore.exe");
                psi.Arguments = url;
                Process.Start(psi);
            }
            Console.Write("Enter authCode> ");
            var authcode = Console.ReadLine();

            try
            {
                vc = VimeoHook.Authorize(
                    authCode: authcode,
                    clientId: Constants.GetVimeoAPIKey(),
                    secret: Constants.GetVimeoAPISecret(),
                    redirect: Constants.GetVimeoRedirectURL()
                    );

                Settings.Default.VimeoAccessCode = vc.AccessToken;
                Settings.Default.Save();
            }
            catch
            {
                App.Error("Error logging in.");
                return;
            }
        }
开发者ID:uptredlabs,项目名称:Shell,代码行数:35,代码来源:VimeoHandler.cs

示例8: produce

        // assignment_stmt = { lvalue " = " } ( expression | new_instance ) terminator ;
        public static Assignment produce(Queue<Token> tokens)
        {
            List<Symbol.Symbol> childSymbols = new List<Symbol.Symbol>();

            // lvalue
            if (tokens.First().tokenType != TokenType.IDENTIFIER)
                return null;

            Token identifierToken = tokens.First();
            Identifier identifier = new Identifier(identifierToken);
            tokens.Dequeue();

            // " is "
            if (tokens.First().tokenType != TokenType.ASSIGNMENT)
            {
                // there is no assign, this might be a method call, stop processing
                tokens.Enqueue(identifierToken);
                return null;
            }
            tokens.Dequeue();

            if (tokens.First().tokenType == TokenType.NEW)
            {
                /*
                // new_instance
                NewInstance newInstance = NewInstanceFactory.produce(symbols);
                if(newInstance == null)
                    throw new ParsingException("NewInstance expected.", symbols.peek());

                // terminator
                optionalTerminator(symbols);

                return Optional.of(new NewInstanceAssignment(identifier, newInstance));
                */
                // TODO: Fix me
                return null;
            }
            else {
                // expression
                Expression expression = ExpressionFactory.produce(tokens);

                // terminator
                optionalTerminator(tokens);

                return new Assignment(identifier, expression);
            }
        }
开发者ID:galderli,项目名称:dp2compiler,代码行数:48,代码来源:AssignmentFactory.cs

示例9: produce

        public static ArgumentList produce(Queue<Token> tokens)
        {
            // <argument_list> ::= <expression> | <argument_list> ", " <expression>

            List<Expression> arguments = new List<Expression>();

            do
            {
                if (tokens.First().tokenType == TokenType.COMMA)
                {
                    tokens.Dequeue();
                }

                Expression expression = ExpressionFactory.produce(tokens);
                arguments.Add(expression);

            } while (tokens.First().tokenType == TokenType.COMMA && tokens.Count != 0);

            return new ArgumentList(arguments);
        }
开发者ID:galderli,项目名称:dp2compiler,代码行数:20,代码来源:ArgumentListFactory.cs

示例10: ReturnsToQueueInReverseOrder

 public void ReturnsToQueueInReverseOrder()
 {
     var queue = new Queue<int>();
     var hourTrack = new Track(queue, 2);
     hourTrack.AddBall(1);
     hourTrack.AddBall(2);
     hourTrack.AddBall(3);
     Assert.AreEqual(0, hourTrack.Length);
     Assert.AreEqual(2, queue.First());
     Assert.AreEqual(3, queue.Last());
 }
开发者ID:c0de,项目名称:BallClock,代码行数:11,代码来源:TrackTests.cs

示例11: processExpression

        private static Expression processExpression(Queue<Token> tokens, int minPrecedence)
        {
            Expression leftHandStatement = producePrimary(tokens);

            while (shouldContinueProcessingTokens(tokens, minPrecedence))
            {
                if (operatorPrecedence[tokens.First().tokenType] < minPrecedence)
                    break;
                Token operat = tokens.First();
                tokens.Dequeue();

                int precedence = operatorPrecedence[operat.tokenType];
                Associativity associativity = operatorAssociativity[operat.tokenType];

                int nextMinPrecedence = associativity == Associativity.LEFT ? precedence + 1 : precedence;

                var rightHandStatement = processExpression(tokens, nextMinPrecedence);
                Expression expression = produceExpression(operat, leftHandStatement, rightHandStatement);
                leftHandStatement = expression;
            }

            return leftHandStatement;
        }
开发者ID:galderli,项目名称:dp2compiler,代码行数:23,代码来源:ExpressionFactory.cs

示例12: ReturnsToQueueInReverseOrderAndAddsBallToNextQueue

 public void ReturnsToQueueInReverseOrderAndAddsBallToNextQueue()
 {
     var queue = new Queue<int>();
     var hourTrack = new Track(queue, 2);
     var minuteTrack = new Track(queue, 2, hourTrack);
     minuteTrack.AddBall(1);
     minuteTrack.AddBall(2);
     minuteTrack.AddBall(3);
     Assert.AreEqual(0, minuteTrack.Length);
     Assert.AreEqual(1, hourTrack.Length);
     Assert.AreEqual(3, hourTrack.First());
     Assert.AreEqual(2, queue.First());
     Assert.AreEqual(1, queue.Last());
 }
开发者ID:c0de,项目名称:BallClock,代码行数:14,代码来源:TrackTests.cs

示例13: T

        private static bool T(ref Queue<Token> tokens)
        {
            Token t = tokens.First();

            if (!TLookup.ContainsKey(t.Type))
                return false;

            List<ParseFunc> functionCalls = TLookup[t.Type];
            foreach (ParseFunc f in functionCalls)
            {
                if (!f(ref tokens))
                    return false;
            }

            return true;
        }
开发者ID:tylorhl,项目名称:SimplePredictiveParser,代码行数:16,代码来源:Parser.cs

示例14: QueueExtensions_First_ReturnsFirstItemInQueue

        public void QueueExtensions_First_ReturnsFirstItemInQueue()
        {
            var queue = new Queue<Int32>();
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);

            var result = queue.First();

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

示例15: Main

    static void Main()
    {
        elementsPosition[] dwarfElements = new elementsPosition[25];
        Random randomGenerator = new Random();

        Console.CursorVisible = false;
        Console.BufferHeight = Console.WindowHeight;

        for (int i = 0; i <= 23; i++)
        {
            dwarfElements[i] = (new elementsPosition(i + (Console.WindowWidth - 10) / 2, Console.WindowHeight - 1));
        }
        for (int i = 0; i <= 23; i++)
        {
            Console.SetCursorPosition(dwarfElements[i].X, dwarfElements[i].Y);
            Console.ForegroundColor = ConsoleColor.DarkGray;

            if (i == 0)
            {
                Console.Write("<");
            }
            if (i > 0 && i < 8)
            {
                Console.Write("-");
            }
            if (i == 8)
            {
                Console.Write(">");
            }
        }

        Queue<elementsPosition> rocks = new Queue<elementsPosition>();
        elementsPosition currentPosition;
        currentPosition.X = 0;
        currentPosition.Y = 0;
        int leftElement = 0;
        int rightElement = 22;
        int count = 0;
        int time = 20;
        int frequency = 5;
        int numberOfMaxRocks = 35;
        elementsPosition p;

        while (true)
        {
            if (count % frequency == 0 && rocks.Count < numberOfMaxRocks)
            {
                currentPosition.X = randomGenerator.Next(1, Console.WindowWidth - 2);
                currentPosition.Y = 0;
                rocks.Enqueue(currentPosition);
            }
            Console.SetCursorPosition(0, 0);

            if (count % 400 == 0)
            {
                time -= 1;
            }

            count++;
            currentPosition.Y = rocks.First().Y + 1;
            currentPosition.X = rocks.First().X;
            rocks.Enqueue(currentPosition);
            Console.SetCursorPosition(currentPosition.X, currentPosition.Y);
            Console.ForegroundColor = (ConsoleColor)randomGenerator.Next(1, 10);
            Console.Write("+");
            p = rocks.Dequeue();
            Console.SetCursorPosition(p.X, p.Y);
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.Write(" ");

            if (rocks.First().Y > Console.WindowHeight - 3)
            {
                for (int i = 0; i < 23; i++)
                    if (dwarfElements[i].X == rocks.First().X)
                    {
                        Console.Clear();
                        Console.SetCursorPosition(0, 0);
                        Console.WriteLine("Game Over!!!");
                        Console.WriteLine("Your Score is {0:0.00}", (count * 1.2) / 3.3);
                        Console.WriteLine("Please click enter to exit");
                        Console.Read();

                        return;
                    }
                p = rocks.Dequeue();
                Console.SetCursorPosition(p.X, p.Y);
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write(" ");
            }

            Thread.Sleep(time);

            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                if (pressedKey.Key == ConsoleKey.RightArrow && (dwarfElements[rightElement].X) < Console.WindowWidth - 2)
                {
                    Console.SetCursorPosition(dwarfElements[rightElement].X, dwarfElements[rightElement].Y);
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.Write("-");
//.........这里部分代码省略.........
开发者ID:Vasil-Pavlov,项目名称:TelerikAcademy,代码行数:101,代码来源:FallingRocks.cs


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