Skip to content

Deque~T~ Class

YuHima edited this page Mar 12, 2024 · 2 revisions

Deque<T> Class

Definition

Represents a double-ended queue for which elements can be added to or removed from the front or back.

public class Deque<T> : ICollection, ICollection<T>, IDeque<T>, IEnumerable, IEnumerable<T>, IList, IList<T>, IReadOnlyCollection<T>, IReadOnlyDeque<T>, IReadOnlyList<T>;

Inheritance: Object → Deque<T>

Implements: ICollection, ICollection<T>, IDeque<T>, IEnumerable, IEnumerable<T>, IList, IList<T>, IReadOnlyCollection<T>, IReadOnlyDeque<T>, IReadOnlyList<T>

Type params

T : The type of elements in the Deque<T>.

Remarks

This supports random-access to the elements contained in the collection and addition of elements to the front or back, or removal from the front or back.

Constructors

Constructor signature Summary
Deque() Initializes a new instance of the Deque<T> class.
Deque(int) Initializes a new instance of the Deque<T> class that is empty and has the specified initial capacity.
Deque(IEnumerable<T>) Initializes a new instance of the Deque<T> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.
Deque(ReadOnlySpan<T>) Initializes a new instance of the Deque<T> class that contains elements copied from the specified span and has sufficient capacity to accommodate the number of the elements copied.

Properties

Property name Summary
this[int] Gets or sets the element at the specified index.
Capacity Gets the number of total elements the Deque<T> can hold without resizing.
Count Gets the number of the elements contained in the Deque<T>.
FrontMargin Gets the number of elements that can be added at the beginning of the Deque<T> without resizing the internal data structure.
IsEmpty Gets the value that indicates whether the Deque<T> is empty.
LastMargin Gets the number of elements that can be added at the end of the Deque<T> without resizing the internal data structure.

Methods

Method name Summary
AsReadOnlySpan() Creates a new read-only span over the Deque<T>.
Clear() Removes all of the elements from the Deque<T>.
Contains(T) Determines whether the Deque<T> contains a specific value.
CopyTo(T[], int) Copies the elements of the Deque<T> to an T[], starting at a particular index.
EnsureCapacity(int) Ensures that the capacity of this Deque<T> is at least the specified one.
EnsureCapacity(int, int) Ensures that the margins at the beginning and back of the Deque<T> are respectively at least those specified.
Find(Predicate<T>) Searches for the first element that matches the conditions defined by the specified Predicate<T>.
FindLast(Predicate<T>) Searches for the last element that matches the conditions defined by the specified Predicate<T>.
GetEnumerator() Returns an enumerator that iterates through the Deque<T>.
IndexOf(T) Searches for the specified item and returns the zero-based index of the first occurrence within the entire Deque<T>.
Insert(int, T) Inserts an item to the Deque<T> at the specified index.
InsertRange(int, IEnumerable<T>) Inserts the elements of the specified collection into the Deque<T> at the specified index.
InsertRange(int, ReadOnlySpan<T>) Inserts the elements of the specified span into the Deque<T> at the specified index.
LastIndexOf(T) Searches for the specified item and returns the zero-based index of the last occurrence within the entire Deque<T>.
PeekFirst() Returns the object at the beginning of the Deque<T> without removing it.
PeekLast() Returns the object at the end of the Deque<T> without removing it.
PopBack() Removes and returns the object at the end of the Deque<T>.
PopBackRange(int) Removes and returns the specified number of objects at the end of the Deque<T>.
PopBackRange(Span<T>) Removes the certain number of objects at the end of the Deque<T> and copies them to the specified span to fill up it.
PopFront() Removes and returns the object at the beginning of the Deque<T>.
PopFrontRange(int) Removes and returns the specified number of objects at the beginning of the Deque<T>.
PopFrontRange(Span<T>) Removes the certain number of objects at the beginning of the Deque<T> and copies them to the specified span to fill up it.
PushBack(T) Adds an object to the end of the Deque<T>.
PushBackRange(IEnumerable<T>) Adds the elements of the specified collection to the end of the Deque<T>.
PushBackRange(ReadOnlySpan<T>) Adds the elements of the specified memory region to the end of the Deque<T>.
PushFront(T) Adds an object to the beginning of the Deque<T>.
PushFrontRange(IEnumerable<T>) Adds the elements of the specified collection to the beginning of the Deque<T>.
PushFrontRange(ReadOnlySpan<T>) Adds the elements of the specified memory region to the beginning of the Deque<T>.
Remove(T) Removes the first occurrence of the specified object from the Deque<T>.
RemoveAt(int) Removes the element at the specified index.
RemoveRange(int, int) Removes a range of elements from the Deque<T>.
Resize(int) Resizes the internal array to the specified size.
ShrinkToFit() Shrink the internal data structure so that the Deque<T> doesn't have any margin at the beginning or end of it.
TryPeekFirst(out T) Returns a value that indicates whether there is an object at the beginning of the Deque<T>, and if one is present, copies it to the item parameter.
TryPeekLast(out T) Returns a value that indicates whether there is an object at the end of the Deque<T>, and if one is present, copies it to the item parameter.
TryPopBack(out T) Returns a value that indicates whether there is an object at the end of the Deque<T>, and if one is present, copies it to the item parameter and removes it from the Deque<T>.
TryPopFront(out T) Returns a value that indicates whether there is an object at the beginning of the Deque<T>, and if one is present, copies it to the item parameter and removes it from the Deque<T>.

Explicit Interface Implementations

Member name Summary
ICollection.CopyTo(Array, int) Copies the elements of the ICollection to an Array, starting at a particular Array index.
ICollection.IsSynchronized Gets a value indicating whether access to the ICollection is synchronized (thread safe).
ICollection.SyncRoot Gets an object that can be used to synchronize access to the ICollection.
ICollection<T>.Add(T)
ICollection<T>.IsReadOnly Gets a value indicating whether the ICollection<T> is read-only.
IEnumerable.GetEnumerator() Returns an enumerator that iterates through a collection.
IEnumerable<T>.GetEnumerator() Returns an enumerator that iterates through a collection.
IList.Add(object) Adds an item to the IList.
IList.Contains(object) Determines whether the IList contains a specific value.
IList.IndexOf(object) Determines the index of a specific item in the IList.
IList.Insert(int, object) Inserts an item to the IList at the specified index.
IList.IsFixedSize Gets a value indicating whether the IList has a fixed size.
IList.IsReadOnly Gets a value indicating whether the IList is read-only.
IList.Remove(object) Removes the first occurrence of a specific object from the IList.
IList.this[int] Gets or sets the element at the specified index.

Clone this wiki locally