本文整理汇总了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);
}
示例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());
}
}
示例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()+ ", ");
}
}
示例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());
}
}
示例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();
}
示例6: EnqueueOne
public void EnqueueOne()
{
var queue = new Queue<string>();
queue.Enqueue("foo");
var item = queue.First();
AssertEquals(item, "foo");
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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());
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
示例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("-");
//.........这里部分代码省略.........