本文整理汇总了C#中System.Collections.Queue.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Peek方法的具体用法?C# Queue.Peek怎么用?C# Queue.Peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public IEnumerator Start()
{
pool = new InventoryPool<InventoryUIItemWrapper>(wrapperPrefab, 8);
queue = new Queue<ItemHolder>(8);
destroyTimer = new WaitForSeconds(slideAnimation.length - 0.025f);
offsetTimer = new WaitForSeconds(offsetTimerSeconds);
foreach (var inv in InventoryManager.GetLootToCollections())
{
inv.OnAddedItem += (items, amount, cameFromCollection) =>
{
if (cameFromCollection == false)
{
queue.Enqueue(new ItemHolder() { item = items.FirstOrDefault(), stackSize = amount});
}
};
}
while (true)
{
if (queue.Count > 0)
{
ShowItem(queue.Peek().item, queue.Peek().stackSize);
queue.Dequeue(); // Remove it
}
yield return offsetTimer;
}
}
示例2: GenerateWorld
public IEnumerator GenerateWorld()
{
bool flip = false;
Queue<Node> current_node = new Queue<Node>();
Queue<Node> tree = new Queue<Node>();
current_node.Enqueue(root);
tree.Enqueue(root);
for(int i=0;i<depth;i++){
for(int j=0;j<current_node.Count;j++){
flip = !flip;
current_node.Peek().Split(flip);
current_node.Enqueue(current_node.Peek().leafs[0]);
current_node.Enqueue(current_node.Peek().leafs[1]);
tree.Enqueue(current_node.Peek().leafs[0]);
tree.Enqueue(current_node.Peek().leafs[1]);
current_node.Dequeue();
}
}
for(int i=0;i<tree.Count;i++){
if(tree.Peek().initAutomata()){
progress+=1/tree.Count;
tree.Dequeue();
}
}
yield return null;
}
示例3: QueueTest
private void QueueTest()
{
Queue queue = new Queue();
queue.Enqueue( CAR_BANK[0] );
queue.Enqueue( CAR_BANK[1] );
queue.Enqueue( CAR_BANK[2] );
((Car)queue.Peek()).Display();
DeQueued( (Car)queue.Dequeue() );
((Car)queue.Peek()).Display();
DeQueued( (Car)queue.Dequeue() );
((Car)queue.Peek()).Display();
DeQueued( (Car)queue.Dequeue() );
try
{
((Car)queue.Peek()).Display();
DeQueued( (Car)queue.Dequeue() );
}
catch (Exception e)
{
Console.WriteLine( "Error!:{0}", e.Message );
}
}
示例4: Main
static void Main(string[] args)
{
// Stack - A LIFO collection
Stack<string> stack = new Stack<string>();
stack.Push("A"); // Push adds to the stack
stack.Push("B");
stack.Push("C");
stack.Push("D");
Console.WriteLine(stack.Peek()); // D - Peek returns the last added value without removing it
Console.WriteLine(stack.Pop()); // D - Pop returna the last added value and removes it
Console.WriteLine(stack.Peek()); // C
// Queue - A FIFO collection
Queue<string> queue = new Queue<string>();
queue.Enqueue("a"); // Enqueue adds to the queue
queue.Enqueue("b");
queue.Enqueue("c");
queue.Enqueue("d");
Console.WriteLine(queue.Peek()); // a - Peek returns the beginning value without removing it
Console.WriteLine(queue.Dequeue()); // a - Dequeue returns the beginning value and removes it
Console.WriteLine(queue.Peek()); // b
//--
Console.ReadKey();
}
示例5: queueButton_Click
private void queueButton_Click(object sender, EventArgs e)
{
Queue fila = new Queue();
//Adicionando itens
fila.Enqueue("Gabriela");
fila.Enqueue("Rafael");
fila.Enqueue("Thiago");
//Exibindo os itens da coleção
foreach (string elemento in fila)
{
listBox1.Items.Add(elemento);
}
listBox1.Items.Add("--------------");
//Exibindo o item primeiro da fila
listBox1.Items.Add("primeiro da fila");
listBox1.Items.Add(fila.Peek());
listBox1.Items.Add("--------------");
//Retirando um elemento da fila (primeiro da fila)
fila.Dequeue();
//Exibindo o item primeiro da fila
listBox1.Items.Add("primeiro da fila");
listBox1.Items.Add(fila.Peek());
}
示例6: Load
public override bool Load(Queue<Token> tokens, Type tokenizerType,TemplateGroup group)
{
Token t = tokens.Dequeue();
Match m;
if (regAlternateFormat.IsMatch(t.Content))
{
m = regAlternateFormat.Match(t.Content);
_variableName = m.Groups[1].Value;
_entryName = m.Groups[2].Value;
string tmp = t.Content.Substring(t.Content.IndexOf("|", m.Groups[2].Index) + 1);
tmp = tmp.Substring(0, tmp.Length - 1);
Tokenizer tok = (Tokenizer)tokenizerType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { tmp});
_children = tok.TokenizeStream(group);
}
else
{
m = regVariableExtractor.Match(t.Content);
_entryName = m.Groups[1].Value;
_variableName = m.Groups[2].Value;
if (regVarValueExtracor.IsMatch(_entryName))
_entryName = regVarValueExtracor.Match(_entryName).Groups[2].Value;
if (regListValueExtracor.IsMatch(_variableName))
_variableName = regListValueExtracor.Match(_variableName).Groups[2].Value;
while ((tokens.Count>0)&&!regEndFor.IsMatch(tokens.Peek().Content))
_children.Add(ComponentExtractor.ExtractComponent(tokens, tokenizerType, group));
if (tokens.Count > 0)
tokens.Dequeue();
}
_entryName = _entryName.Trim();
_variableName = _variableName.Trim();
return true;
}
示例7: Main_7_9_6
//Main_7_9_6
public static void Main_7_9_6()
{
Queue myQueue = new Queue();
//��Queueβ�����Ԫ��
myQueue.Enqueue("��");
myQueue.Enqueue("��");
myQueue.Enqueue("˭");
//����Queueu��ʼ��Ԫ��
Console.WriteLine(myQueue.Peek());
//���ز��Ƴ�Queue��ʼ��Ԫ��
myQueue.Dequeue();
//����Queue
foreach (object o in myQueue)
Console.WriteLine(o.ToString());
Stack myStack = new Stack();
//��Stack��������Ԫ��
myStack.Push("��");
myStack.Push("��");
myStack.Push("˭");
//����Stack������Ԫ��
Console.WriteLine(myStack.Peek());
//���ز��Ƴ�Stack������Ԫ��
myStack.Pop();
//����Stack
foreach (object o in myStack)
Console.WriteLine(o.ToString());
}
示例8: GetMinDiceThrows
public static int GetMinDiceThrows(int[] board, int board_size)
{
bool[] visited = new bool[board_size];
for (int i = 0; i < board_size; i++)
{
visited[i] = false;
}
visited[0] = true;
Queue que = new Queue();
SnakeNLadder queEntry = new SnakeNLadder(0, 0);
que.Enqueue(queEntry);
SnakeNLadder item = (SnakeNLadder)que.Peek();
while (que.Count > 0)
{
item = (SnakeNLadder) que.Peek();
int vertex = item.v;
//Ending condition: We're at the last piece;
if (vertex == board_size - 1)
{
break;
}
que.Dequeue();
/* 1 ~ 6 dice here, also cannot exceed board size for obvious reason
*/
for (int j = vertex +1; j <= (vertex + 6) && j < board_size; j++)
{
if (!visited[j])
{
SnakeNLadder entry = new SnakeNLadder(j, item.dist + 1);
visited[j] = true;
//if we ru n into a ladder or snake here...
if (board[j] != -1)
{
entry.v = board[j];
}
que.Enqueue(entry);
}
}
}
return item.dist;
}
示例9: ExecuteAlgorithm
private void ExecuteAlgorithm(int x, int y, IsValidHandler isValid, PointActionHandler action)
{
///Flood-Fill algorithm
Queue<Point> q = new Queue<Point>();
if (regionMask[x, y])
return;
q.Enqueue(new Point(x, y));
while (q.Count > 0)
{
Point p = q.Peek();
int x1 = p.X;
int y1 = p.Y;
if (isValid.Invoke(p))
{
action.Invoke(p.X, p.Y);
}
if (isValid.Invoke(new Point(x1, y1 + 1)))
{
action.Invoke(x1, y1 + 1);
q.Enqueue(new Point(x1, y1 + 1));
}
if (isValid.Invoke(new Point(x1, y1 - 1)))
{
action.Invoke(x1, y1 - 1);
q.Enqueue(new Point(x1, y1 - 1));
}
if (isValid.Invoke(new Point(x1 + 1, y1)))
{
action.Invoke(x1 + 1, y1);
q.Enqueue(new Point(x1 + 1, y1));
}
if (isValid.Invoke(new Point(x1 - 1, y1)))
{
action.Invoke(x1 - 1, y1);
q.Enqueue(new Point(x1 - 1, y1));
}
q.Dequeue();
if (border)
{
q.Clear();
depth = Int32.MaxValue;
}
}
///end of Flood-Fill algorithm
}
示例10: doBFS
private static void doBFS(int[][] matrix, int x, int y)
{
Queue q = new Queue();
int tmp;
int xx, yy;
int i;
int dist;
q.Enqueue(x * m + y);
while (q.Count>0) {
tmp = (int)q.Peek();
q.Dequeue();
x = tmp / m;
y = tmp % m;
dist = matrix[x][y] > 0 ? matrix[x][y] : 0;
for (i = 0; i < 4; ++i) {
// one of 4 neighbors -
xx = x + dd[i,0];
yy = y + dd[i,1];
// boundary check - avoid duplication calculations as well
// the order is also important; in the array; and then,
// check node is not room;
// and then, node is already with less steps
//
if (
// node is out of boundary of matrix
!inBound(xx, yy) || // node is not room - secondary check
matrix[xx][yy] < 0 || // node visited has less steps to a guard
(matrix[xx][yy] > 0 && matrix[xx][yy] <= dist + 1)) {
// out of boundary
// a guard or a blockade
// the distance is no shorter
continue;
} // if the node on the queue is the Guard node, (value: -1)
bool queuedNodeIsGuard = (dist == 0); //
bool queueNodeIsRoom = (dist >= 1);
if (queuedNodeIsGuard)
matrix[xx][yy] = 1;
// else if the node on the queue is a room, need to compare the distance
else if (queueNodeIsRoom )
{
// keep minimum value
bool neverCalculated = matrix[xx][yy] == 0;
bool hasHighSteps = matrix[xx][yy] > dist + 1;
bool needUpdate = (neverCalculated || hasHighSteps);
if(needUpdate)
matrix[xx][yy] = dist+1;
}
q.Enqueue(xx * m + yy);
}
}
}
示例11: PeekShouldPeekSourceQueue
public void PeekShouldPeekSourceQueue()
{
// arrange
var source = new Queue<object>();
var target = new QueueAdapter<object>( source );
// act
target.Enqueue( new object() );
// assert
Assert.Equal( source.Peek(), target.Peek() );
}
示例12: MostrarCola
public void MostrarCola(ListBox lista, Queue cola, Label turno)
{
lista.Items.Clear();
//Mostrar los valores
foreach (Persona item in cola)
lista.Items.Add(item);
if (cola.Count > 0)
turno.Text = String.Format("Turno: {0}", cola.Peek());
else
turno.Text = "Sin elementos";
}
示例13: MostrarCola
public void MostrarCola(ListBox lista,Queue Cola, Label turno)
{
//Limpiando los valores
lista.Items.Clear();
//Mostrando los valores
foreach (Persona item in Cola)
lista.Items.Add(item);//Si agregas un . despues de item .Nombre solo aparece el nombre en el listbox
if (Cola.Count > 0)
{
turno.Text = String.Format("Turno: {0}", Cola.Peek());
}
else
turno.Text = "Sin elementos";
}
示例14: MostrarCola
public void MostrarCola(ListBox lista, Queue cola, Label turno)
{
// Limpiando Valores
lista.Items.Clear();
// Mostrando los valores
foreach (Persona item in cola)
lista.Items.Add(item);
if (cola.Count > 0)
{
turno.Text = String.Format("Turno: {0}", cola.Peek()); // peek es para saber cual es el ultimo de la cola
}
else turno.Text = "Sin elementos";
}
示例15: Start
void Start()
{
_instrument = transform.parent.GetComponentInChildren<Instrument>();
char[] splitters = { '\n' };
string[] allStringTimings = trackFile.text.Split(splitters);
_noteTimings = new Queue();
foreach(string s in allStringTimings) {
if(!string.IsNullOrEmpty(s)) {
_noteTimings.Enqueue((float) Convert.ToInt32(s));
}
}
_startTime = Time.time;
Debug.Log(_noteTimings.Peek());
}