本文整理汇总了C#中System.Collections.Queue.Dequeue方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Dequeue方法的具体用法?C# Queue.Dequeue怎么用?C# Queue.Dequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Dequeue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillQueue
private static void FillQueue(int firstX, int firstY, byte currColor, byte destColor)
{
Queue<Tuple<int, int>> q = new Queue<Tuple<int, int>>();
q.Enqueue(Tuple.Create(firstX, firstY));
var maxX = _data.GetLength(0);
var maxY = _data.GetLength(1);
while (q.Count > 0)
{
var point = q.Dequeue();
var x = point.Item1;
var y = point.Item2;
if (_data[x, y] == destColor)
continue;
if (_data[x, y] != currColor)
continue;
_data[x, y] = destColor;
if (x + 1 < maxX)
q.Enqueue(Tuple.Create(x + 1, y));
if (x - 1 >= 0)
q.Enqueue(Tuple.Create(x - 1, y));
if (y + 1 < maxY)
q.Enqueue(Tuple.Create(x, y + 1));
if (y - 1 >= 0)
q.Enqueue(Tuple.Create(x, y - 1));
Display(_data);
}
}
示例2: getTypes
private static IEnumerable<Type> getTypes(Type sourceType)
{
Queue<Type> pending = new Queue<Type>();
HashSet<Type> visited = new HashSet<Type>();
pending.Enqueue(sourceType);
while (pending.Count != 0)
{
Type type = pending.Dequeue();
visited.Add(type);
yield return type;
if (type.BaseType != null)
{
if (!visited.Contains(type.BaseType))
{
pending.Enqueue(type.BaseType);
}
}
foreach (Type interfaceType in type.GetInterfaces())
{
if (!visited.Contains(interfaceType))
{
pending.Enqueue(interfaceType);
}
}
}
}
示例3: 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;
}
}
示例4: Run
static void Run (Queue q)
{
MergeContext context = GetDefaultContext ();
while (q.Count > 0) {
string token = (string) q.Dequeue ();
if (token.Length < 2)
Usage ();
if (token [0] == '-' && token [1] == '-') {
if (token.Length < 3)
Usage ();
switch (token [2]) {
case 'v':
Version ();
break;
case 'a':
About ();
break;
default:
Usage ();
break;
}
}
if (token [0] == '-' || token [0] == '/') {
token = token.Substring (1);
if (token == "o" || token == "out")
context.OutputPath = (string) q.Dequeue ();
else if (token == "e" || token == "exe")
context.OutputIsExecutable = true;
else if (token == "d" || token == "dll")
context.OutputIsExecutable = false;
else if (token == "L")
context.NativeLibraries.LibrariesSearchPaths.Add ((string) q.Dequeue ());
else if (token == "l")
context.NativeLibraries.Libraries.Add ((string) q.Dequeue ());
else
Usage ();
} else {
context.Assemblies.Add (token);
while (q.Count > 0)
context.Assemblies.Add ((string) q.Dequeue ());
}
}
if (context.Assemblies.Count < 2)
Error ("At least two assemblies needed");
if (context.OutputPath == "")
Error ("Please set output filename");
context.NativeLibraries.Libraries.Add ("c");
context.NativeLibraries.LibrariesSearchPaths.Add ("/lib");
context.NativeLibraries.Initialize ();
context.Link ();
}
示例5: 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 );
}
}
示例6: Mai
static void Mai(string[] args)
{
//Cola.
Queue q = new Queue();
q.Enqueue("A");
q.Enqueue(new Persona());
Console.WriteLine(q.Dequeue());
Console.WriteLine(q.Dequeue());
//Es lo mas parecido a un array dinamico
ArrayList p = new ArrayList();
p.Add(new Persona());
p.Add(new Persona());
p.Add("Pepe");
p.Add(new Persona());
p.Add(new Persona());
p.Add("");
p.Add(new Persona());
Console.WriteLine(p[2]);
Console.ReadLine();
//Diccionario. Estructura de datos que se almacena con claves.
//Para usarlo llamaremos directamente a la clave.
}
示例7: Handle
public override bool Handle(object input, Queue<string> tokens)
{
var elementType = _property.PropertyType.GetGenericArguments().First();
var list = typeof(List<>).CloseAndBuildAs<IList>(elementType);
var wasHandled = false;
var flag = "";
if (tokens.NextIsFlagFor(_property))
{
flag = tokens.Dequeue();
while (tokens.Count > 0 && !tokens.NextIsFlag())
{
var value = _converter.FromString(tokens.Dequeue(), elementType);
list.Add(value);
wasHandled = true;
}
if(!wasHandled)
{
throw new InvalidUsageException("No values specified for flag {0}.".ToFormat(flag));
}
_property.SetValue(input, list, null);
}
return wasHandled;
}
示例8: getDirections
// times out for large values of x and y, since it is essentially scanning all the points on the coordinate space
public int getDirections(int x, int y)
{
int curx, cury, dist;
curx = cury = dist = 0;
Queue q = new Queue();
q.Enqueue(0); q.Enqueue(0); q.Enqueue(0);
while (q.Count != 0)
{
curx = (int)q.Dequeue();
cury = (int)q.Dequeue();
dist = (int)q.Dequeue();
if (curx == x && cury == y)
{
return dist;
}
// -ve % 2 can result in -ve
// -ve % 2 won't be -ve when remainder is zero
// so checking for zero is safer
int dy = ((curx+2) % 2 == 0) ? 1 : -1;
int dx = ((cury+2) % 2 == 0) ? 1 : -1;
q.Enqueue(curx); q.Enqueue(cury + dy); q.Enqueue(dist + 1);
q.Enqueue(curx + dx); q.Enqueue(cury); q.Enqueue(dist + 1);
}
// path not found
return -1;
}
示例9: 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;
}
示例10: Mai
static void Mai(string[] args)
{
//4 algoritmos para almacenar informacion.
//1.Colas (FIFO)
//2.Pilas (LIFO)
//3.Listas (Array dinamico, se accede a su informacion por el indice)
//4.Diccionarios ()
//5.Set()
//Cola
Queue q=new Queue();
q.Enqueue("A");
q.Enqueue(new Persona());//Enqueue para meter datos
Console.WriteLine(q.Dequeue());//El dequeue para sacar datos
Console.WriteLine(q.Dequeue());
ArrayList l=new ArrayList();
l.Add(new Persona());
l.Add(new Persona());
l.Add(new Persona());
l.Add(new Persona());
l.Add("Pepo");
l.Add(23);
l.Add(new Persona());
l.Add(new Persona());
Console.WriteLine(l[4]);
Console.ReadLine();
}
示例11: Write
public void Write(string message) {
string[] splitted = message.Split(new string[] {"\n"}, StringSplitOptions.None);
Queue<string> queue = new Queue<string>(splitted);
string first = queue.Dequeue();
while (queue.Count > 0) {
Strings.Add(new LineInfo(queue.Dequeue()));
}
}
示例12: ByteArrayToBitmap
public static Bitmap ByteArrayToBitmap(byte[] rgbComponents, int width, int hight)
{
Queue<byte> rgbComponentQueue = new Queue<byte>(rgbComponents);
Bitmap bitmap = new Bitmap(width, hight);
for (int y = 0; y < hight; y++)
{
for (int x = 0; x < width; x++)
{
bitmap.SetPixel(x, y, Color.FromArgb(rgbComponentQueue.Dequeue(), rgbComponentQueue.Dequeue(), rgbComponentQueue.Dequeue()));
}
}
return bitmap;
}
示例13: Mai
static void Mai(string[] args)
{
/*En una coleccción se accede a sus elementos a traves de su indice,
de la misma forma que sucede en un Array*/
/*Tipos de colecciones: es "el que" queremos guardar*/
/*Algoritmos de alamacenaje: es "como" lo queremos guardar*/
/*Existen distintos algoritmos para almacenar y recuperar los objetos*/
/*4 formas de gestion de información
- Colas: no se accede deirectamente a la información FIFO. Ventajas, utiliza pocos
recursos de memoria, es facil y rapida de utilizar.
- Pilas: funciona del mismo modo que una cola, pero la ultima información que introduce
es la primera que sale. LIFO last In first Out.
- Listas: Es lo más similar a un Array. Es un array dinamico. Se accede a los elementos
por su indice. Un array de objetos es mucho más dinamico que uno convencional.
- Diccionarios: es una estructura de datos que a cada objeto que almacena contiene s
propia clave.Ej. DNI.
- Set: no se almacena el orden. Solo almacena la información. Sirve para guardar gran
cantidad en memoria de forma rapida y eficiente.
*/
ArrayList l = new ArrayList();
l.Add(new Persona());
l.Add(new Persona());
l.Add("Pepo");
l.Add(new Persona());
l.Add(new Persona());
l.Add(23);
l.Add(new Persona());
Console.WriteLine(l[2]);
/*Colas(Queue): FIFO first In first Out, se recupera la información en el mismo orden en el que se ha introducido*/
Queue q = new Queue();
q.Enqueue("A");
q.Enqueue(new Persona());
Console.WriteLine(q.Dequeue()); //recupera el primer objeto
Console.WriteLine(q.Dequeue()); //recupero el segundo objeto
Console.ReadLine();
}
示例14: BFS
public void BFS(VNode v)
{
/*使用队列来实现广度优先搜索
*/
Queue<VNode> q = new Queue<VNode>();
v.Visited = true;
q.Enqueue(v);
Console.WriteLine("Visit:{0}", v.Data);
while (q.Count > 0)
{
var vnode = q.Dequeue();
var enode = vnode.FirstEdge;
while (null != enode)
{
if (!enode.Adj.Visited)
{
enode.Adj.Visited = true;
Console.WriteLine("Visit:{0}", enode.Adj.Data);
q.Enqueue(enode.Adj);
}
enode = enode.Next;
}
}
}
示例15: BreadthFirstSearch
public IList BreadthFirstSearch(BatteryStation s)
{
UnmarkAll();
IList l = new ArrayList();
Queue<BatteryStation> q = new Queue<BatteryStation>();
q.Enqueue(s);
l.Add(s);
s.Mark = true;
while (q.Count > 0)
{
BatteryStation n = q.Dequeue();
BatteryStation c = null;
while ((c = GetNextUnMarked(GetAdjacencies(n))) != null)
{
c.Mark = true;
q.Enqueue(c);
l.Add(c);
}
}
return l;
}