Queue

Páginas: 7 (1705 palabras) Publicado: 13 de noviembre de 2012
Queue (Clase)
Representa una colección de objetos de tipo "primero en entrar, primero en salir".
Espacio de nombres: System.Collections
Ensamblado: mscorlib (en mscorlib.dll)
Sintaxis

C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class Queue : ICollection, IEnumerable, ICloneable
Comentarios

Las colas son útiles paraalmacenar mensajes en el orden en el que fueron recibidos para el procesamiento secuencial. Esta clase implementa una cola como una matriz circular. Los objetos almacenados en Queue se insertan en un extremo y se quitan del otro.
La capacidad de Queue es el número de elementos que Queue puede contener. La capacidad inicial predeterminada de Queue es 32. A medida que se agregan elementos a unacolección Queue, la capacidad aumenta automáticamente según lo requiera la reasignación. La capacidad se puede disminuir si se llama al método TrimToSize.
El factor de crecimiento es el número por el cual se multiplica la capacidad actual cuando se requiere una capacidad mayor. El factor de crecimiento se determina al construir la clase Queue. El factor de crecimiento predeterminado es 2,0.
Laclase Queue acepta referencia de objeto null (Nothing en Visual Basic) como valor válido y admite elementos duplicados.
Queue<T>.Enqueue Method
Adds an object to the end of the Queue<T>.
Namespace:  System.Collections.Generic
Assembly:  System (in System.dll)
Syntax

C#
public void Enqueue(
T item
)
Parameters
item
Type: T
The object to add to the Queue<T>. The valuecan be null for reference types.
Remarks

If Count already equals the capacity, the capacity of the Queue<T> is increased by automatically reallocating the internal array, and the existing elements are copied to the new array before the new element is added.
If Count is less than the capacity of the internal array, this method is an O(1) operation. If the internal array needs to bereallocated to accommodate the new element, this method becomes an O(n) operation, where n is Count.
Examples

The following code example demonstrates several methods of the Queue<T> generic class, including the Enqueue method.
The code example creates a queue of strings with default capacity and uses the Enqueue method to queue five strings. The elements of the queue are enumerated, whichdoes not change the state of the queue. The Dequeue method is used to dequeue the first string. The Peek method is used to look at the next item in the queue, and then theDequeue method is used to dequeue it.
The ToArray method is used to create an array and copy the queue elements to it, then the array is passed to the Queue<T> constructor that takes IEnumerable<T>, creating a copy ofthe queue. The elements of the copy are displayed.
An array twice the size of the queue is created, and the CopyTo method is used to copy the array elements beginning at the middle of the array. The Queue<T> constructor is used again to create a second copy of the queue containing three null elements at the beginning.
The Contains method is used to show that the string "four" is in thefirst copy of the queue, after which the Clear method clears the copy and the Count property shows that the queue is empty.

Queue.Enqueue Method
Adds an object to the end of the Queue.
[Visual Basic]
Public Overridable Sub Enqueue( _
ByVal obj As Object _
)
[C#]
public virtual void Enqueue(
object obj
);
[C++]
public: virtual void Enqueue(
Object* obj
);
[JScript]
publicfunction Enqueue(
obj : Object
);
Parameters
obj
The object to add to the Queue. The value can be a null reference (Nothing in Visual Basic).
Remarks
If Count already equals the capacity of the Queue, the capacity is increased by automatically reallocating the internal array before copying the old elements and adding the new element. The new capacity is determined by multiplying the current...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • queu te digo
  • bachiller en medicina natural queue es alcachofa
  • JavaMessage Queue
  • Sql Server Waits Queues
  • novela por queue a mi valeria piassa polizzi
  • Perspectives On Queues, Social Justice And The Psychology Of Queuing
  • “Suggesting queue-jumping: ethical justification for an informal resources allocation practice

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS