本文整理汇总了C#中System.Collections.Queue.First方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.First方法的具体用法?C# Queue.First怎么用?C# Queue.First使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.First方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: produce
public static If produce(Queue<Token> tokens)
{
expect(tokens, TokenType.IF);
Expression expression = ExpressionFactory.produce(tokens);
expect(tokens, TokenType.DO);
Block block = BlockFactory.produce(tokens);
if (tokens.Count != 0 && tokens.First().tokenType == TokenType.ELSE)
{
tokens.Dequeue();
Block elseBlock = null;
if (tokens.First().tokenType == TokenType.IF)
{
Token firstBlockToken = tokens.First();
If ifSymbol = produce(tokens);
List<Statement> elseBlockSymbolList = new List<Statement> {ifSymbol};
elseBlock = new Block(firstBlockToken, elseBlockSymbolList);
}
else {
expect(tokens, TokenType.DO);
elseBlock = BlockFactory.produce(tokens);
}
return new If(expression, block, elseBlock);
}
return new If(expression, block);
}
示例2: produce
public static Block produce(Queue<Token> tokens)
{
List<Statement> statements = new List<Statement>();
Token firstBlockToken = tokens.First();
expect(tokens, TokenType.INDENT);
while (tokens.Count != 0)
{
Statement statement = StatementFactory.produce(tokens);
if(statement == null)
break;
statements.Add(statement);
}
expect(tokens, TokenType.DEDENT);
return new Block(firstBlockToken, statements);
}
示例3: produce
public static Primitive produce(Queue<Token> tokens)
{
Token token = tokens.First();
string content = token.content;
Primitive primitive = null;
if (token.tokenType == TokenType.BOOLEAN)
{
tokens.Dequeue();
content = content.ToLower();
primitive = new Bool(token, content == "true");
}
else if (token.tokenType == TokenType.TEXT)
{
tokens.Dequeue();
primitive = new Text(token, content);
}
else if( token.tokenType == TokenType.NUMBER)
{
tokens.Dequeue();
primitive = new Number(token, Convert.ToDouble(content));
}
return primitive;
}
示例4: fallingWords
private static void fallingWords(Random ran, string[] textToArrey, int wordsCount, DateTime start)
{
int randomWordIndesx = ran.Next(0, textToArrey.Length);
int randomWordPosition = ran.Next(10, 60);
string curentWordString = textToArrey[randomWordIndesx];
Queue<char> que = new Queue<char>();
foreach (var letter in curentWordString)
{
que.Enqueue(letter);
}
for (int i = 0; ; i++)
{
if (que.Count == 0)
{
wordsCount++;
fallingWords(ran, textToArrey, wordsCount, start);
break;
}
Console.Clear();
char pressedBuon = new char();
if (Console.KeyAvailable)
{
ConsoleKeyInfo a = Console.ReadKey();
pressedBuon = a.KeyChar;
Console.Clear();
}
// var tem = que.First();
if (que.First() == pressedBuon)
{
que.Dequeue();
}
if (i == Console.BufferHeight)
{
DateTime end = DateTime.Now;
Console.SetCursorPosition(0, 0);
Console.WriteLine("GAME OVER");
var playedTime = end - start;
int min = 0;
if (playedTime.Minutes > min)
{
min = playedTime.Minutes;
}
double playedTimeInSeconds = playedTime.Seconds + (min * 60);
double wordsPerSecond = wordsCount / playedTimeInSeconds;
Console.WriteLine("Words per minute: {0:0.#}", wordsPerSecond * 60);
//Console.WriteLine("play time {0}",playedTime);
//Console.WriteLine("seconds={0}",playedTimeInSeconds);
//Console.WriteLine(wordsCount);
break;
}
//print
Console.SetCursorPosition(randomWordPosition, i);
Console.Write(new string(' ', curentWordString.Length - que.Count));
foreach (var letter in que)
{
Console.Write(letter);
}
//sleep++
Thread.Sleep(400);
}
}
示例5: BFS
public void BFS(int sx, int sy, int threshhold = 2)
{
visit = new bool[WIDTH, WIDTH];
score = new double[WIDTH, WIDTH];
prev = new Tuple<int, int>[WIDTH, WIDTH];
Queue<Tuple<double, Tuple<int, int>>> q = new Queue<Tuple<double, Tuple<int, int>>>();
q.Enqueue(new Tuple<double, Tuple<int, int>>(1, new Tuple<int, int>(sx, sy)));
List<int> dx = new List<int>();
List<int> dy = new List<int>();
for (int i = -threshhold; i <= threshhold; i++)
for (int j = -threshhold; j <= threshhold; j++)
{
dx.Add(i);
dy.Add(j);
}
int loop = 0;
bool visitTag = false;
while (q.Count > 0)
{
Tuple<double, Tuple<int, int>> min = q.First();
int x = min.Item2.Item1;
int y = min.Item2.Item2;
if (visit[x, y])
{
q.Dequeue();
continue;
}
loop++;
//if (loop % 100 == 0)
visit[x, y] = true;
for (int i = 0; i < dx.Count; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0) continue;
if (nx >= WIDTH) continue;
if (ny < 0) continue;
if (ny >= WIDTH) continue;
if (visit[nx, ny])
continue;
if (tagMap[nx, ny])
{
visitTag = true;
}
else
{
if (visitTag)
continue;
}
double newscore = score[x, y] + 1;
double oldscore = score[nx, ny];
if (oldscore == 0 || oldscore > newscore)
{
score[nx, ny] = newscore;
prev[nx, ny] = new Tuple<int, int>(x, y);
q.Enqueue(new Tuple<double, Tuple<int, int>>(newscore, new Tuple<int, int>(nx, ny)));
}
}
q.Dequeue();
}
}