1 Temmuz 2019 Pazartesi

ArrayDeque Sınıfı

Giriş
Şeklen şöyle


C++ İle Farkı
ArrayDequeue C++'daki gibi bucket'ler ile çalışmaz. Array'i circular buffer gibi kullanır. Buffer dolunca kapasitesini iki katına çıkarır ve yeni array'i düzleştirir. Şeklen şöyle


constructor
İmzası şöyle. Verilen kapasite dolar dolmaz 2 katına çıkarılır.
public class ArrayDeque<E> extends AbstractCollection<E>
                           implements Deque<E>, Cloneable, Serializable
{
    /**
     * The array in which the elements of the deque are stored.
     * The capacity of the deque is the length of this array, which is
     * always a power of two. The array is never allowed to become
     * full, except transiently within an addX method where it is
     * resized (see doubleCapacity) immediately upon becoming full,
     * thus avoiding head and tail wrapping around to equal each
     * other....
Örnek
Şöyle yaparız.
ArrayDeque<int> deque = new ArrayDeque<int>(10); // Create a queue 
addLast metodu
Şöyle yaparız.
int i = 1;
deque.addLast(i);
removeFirst metodu
Şöyle yaparız.
int temp = deque.removeFirst(); // Take the first item from the deque
removeLastOccurence metodu
İmzası şöyle.
/**
  * Removes the last occurrence of the specified element in this
  * deque (when traversing the deque from head to tail).
  * If the deque does not contain the element, it is unchanged.
  * More formally, removes the last element {@code e} such that
  * {@code o.equals(e)} (if such an element exists).
  * Returns {@code true} if this deque contained the specified element
  * (or equivalently, if this deque changed as a result of the call).
  *
  * @param o element to be removed from this deque, if present
  * @return {@code true} if the deque contained the specified element
  */
 public boolean removeLastOccurrence(Object o);

Hiç yorum yok:

Yorum Gönder