/** * Returns the element at the specified position in Bag. * * @param index * index of the element to return * * @return the element at the specified position in bag * * @throws ArrayIndexOutOfBoundsException */ public int get(int index) throws ArrayIndexOutOfBoundsException { return elements[index(index)]; }
/** * Returns the element at the specified position in Bag. * * @param index * index of the element to return * * @return the element at the specified position in bag * * @throws ArrayIndexOutOfBoundsException */ public int get(int index) throws ArrayIndexOutOfBoundsException { return elements[index(index)]; }
/** * Check if bag contains this element. * * @param e * element to check * * @return {@code true} if the bag contains this element */ public boolean contains(int e) { for(int i = 0; size > i; i++) { if(e == elements[index(i)]) { return true; } } return false; }
/** * Check if bag contains this element. * * @param e * element to check * * @return {@code true} if the bag contains this element */ public boolean contains(int e) { for(int i = 0; size > i; i++) { if(e == elements[index(i)]) { return true; } } return false; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("IntDeque("); for (int i = 0; size > i; i++) { if (i > 0) sb.append(", "); sb.append(elements[index(i)]); } sb.append(')'); return sb.toString(); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("IntDeque("); for (int i = 0; size > i; i++) { if (i > 0) sb.append(", "); sb.append(elements[index(i)]); } sb.append(')'); return sb.toString(); } }
public int popLast() { assertNotEmpty(); int index = index(--size); int value = elements[index]; return value; }
public int popLast() { assertNotEmpty(); int index = index(--size); int value = elements[index]; return value; }
/** * Adds the specified element to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param e * element to be added to this list */ public void add(int e) { if (size == elements.length) grow((elements.length * 7) / 4 + 1); elements[index(size++)] = e; }
/** * Set element at specified index in the bag. * * @param index * position of element * @param e * the element */ public void set(int index, int e) { if(index >= elements.length) { grow((index * 7) / 4 + 1); } size = Math.max(size, index + 1); elements[index(index)] = e; }
/** * Set element at specified index in the bag. * * @param index * position of element * @param e * the element */ public void set(int index, int e) { if(index >= elements.length) { grow((index * 7) / 4 + 1); } size = Math.max(size, index + 1); elements[index(index)] = e; }
/** * Adds the specified element to the end of this bag. * <p> * If required, it also increases the capacity of the bag. * </p> * * @param e * element to be added to this list */ public void add(int e) { if (size == elements.length) grow((elements.length * 7) / 4 + 1); elements[index(size++)] = e; }