Queue accepts null as a valid value and allows duplicate elements.įor the generic version of this collection, see For example, a Queue with a growth factor of 1.0 will always increase in capacity by four when a greater capacity is required. The capacity of the Queue will always increase by at least a minimum of four, regardless of the growth factor. The growth factor is determined when the Queue is constructed. The growth factor is the number by which the current capacity is multiplied when a greater capacity is required. The capacity can be decreased by calling TrimToSize. As elements are added to a Queue, the capacity is automatically increased as required through reallocation. The capacity of a Queue is the number of elements the Queue can hold. Peek returns the oldest element that is at the start of the Queue but does not remove it from the Queue. Three main operations can be performed on a Queue and its elements:Įnqueue adds an element to the end of the Queue.ĭequeue removes the oldest element from the start of the Queue. Use ConcurrentQueue or ConcurrentStack if you need to access the collection from multiple threads concurrently. Use Stack if you need to access the information in reverse order. Use Queue if you need to access the information in the same order that it is stored in the collection. Queues and stacks are useful when you need temporary storage for information that is, when you might want to discard an element after retrieving its value. For more information, see Non-generic collections shouldn't be used on GitHub. Instead, we recommend that you use the generic Queue class. We don't recommend that you use the Queue class for new development. Objects stored in a Queue are inserted at one end and removed from the other. This class implements a queue as a circular array. ' This code produces the following output. Public Shared Sub PrintValues(m圜ollection As IEnumerable) Displays the properties and values of the Queue.Ĭonsole::WriteLine( "\tCount: ", myQ.Count) Void PrintValues( IEnumerable^ m圜ollection ) The following example shows how to create and add values to a Queue and how to print out its values. ICollection IEnumerable ICloneable Examples Implements ICloneable, ICollection Inheritance Implements ICollection Public Class Queue Public class Queue : ICloneable, type Queue = class public ref class Queue : System::Collections::ICollection public ref class Queue : ICloneable, System::Collections::ICollection public class Queue : public class Queue : ICloneable, Represents a first-in, first-out collection of objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |