/** * Gets the index to the last element if it exists. * @return The index of the last element (tail) or -1 if no elements exist. */ public long getLast() { if (isEmpty()) { return -1; } // next points to current free space, so the one directly before it // would actually be the last item // NOTE: -1 mod 4 = 3 (isn't the modulus operator schweet?) //return ((next - 1) % capacity); return calculateNewIndex(next, -1); }
/** * Adds an element to the back of the index if its not full. * @return True if the element was added or false if the index was full. */ public boolean addLast() { // check if queue is full if (isFull()) { return false; } // increment next available space, rollover to beginning if needed next = calculateNewIndex(next, 1); //next = (next + 1) % capacity; // always increment size size++; return true; }
/** * Gets the index to the last element if it exists. * @return The index of the last element (tail) or -1 if no elements exist. */ public long getLast() { if (isEmpty()) { return -1; } // next points to current free space, so the one directly before it // would actually be the last item // NOTE: -1 mod 4 = 3 (isn't the modulus operator schweet?) //return ((next - 1) % capacity); return calculateNewIndex(next, -1); }
/** * Adds an element to the front of the index if its not full. * @return True if the element was added or false if the index was full. */ public boolean addFirst() { // check if queue is full if (isFull()) { return false; } // increment next available space, rollover to beginning if needed first = calculateNewIndex(first, -1); //first = (first - 1) % capacity; // always increment size size++; return true; }
/** * Adds an element to the front of the index if its not full. * @return True if the element was added or false if the index was full. */ public boolean addFirst() { // check if queue is full if (isFull()) { return false; } // increment next available space, rollover to beginning if needed first = calculateNewIndex(first, -1); //first = (first - 1) % capacity; // always increment size size++; return true; }
/** * Adds an element to the back of the index if its not full. * @return True if the element was added or false if the index was full. */ public boolean addLast() { // check if queue is full if (isFull()) { return false; } // increment next available space, rollover to beginning if needed next = calculateNewIndex(next, 1); //next = (next + 1) % capacity; // always increment size size++; return true; }
/** * Gets the index where the next first element will be put. This is the index * where the next "addFirst" operation would put the element. Will return -1 if * the index is full (i.e. no next space available). * @return The index of where the next first element will be put or -1 if the * the index is full. */ public long getNextFirst() { if (isFull()) { return -1; } else if (isEmpty()) { // interesting case, always the current first return first; } else { return calculateNewIndex(first, -1); } }
/** * Gets the index where the next first element will be put. This is the index * where the next "addFirst" operation would put the element. Will return -1 if * the index is full (i.e. no next space available). * @return The index of where the next first element will be put or -1 if the * the index is full. */ public long getNextFirst() { if (isFull()) { return -1; } else if (isEmpty()) { // interesting case, always the current first return first; } else { return calculateNewIndex(first, -1); } }
/** * Removes the last element from the back of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeLast() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed next = calculateNewIndex(next, -1); //next = (next - 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }
/** * Removes the first element from the front of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeFirst() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed first = calculateNewIndex(first, 1); //first = (first + 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }
/** * Removes the first element from the front of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeFirst() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed first = calculateNewIndex(first, 1); //first = (first + 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }
/** * Removes the last element from the back of the index if its not empty. * @return True if the element was removed or false if the index was empty. */ public boolean removeLast() { // check if queue is empty if (isEmpty()) { return false; } // increment first item, rollver to beginning if needed next = calculateNewIndex(next, -1); //next = (next - 1) % capacity; // always decrement size size--; // check if we should reset checkReset(); return true; }
this.next = this.calculateNewIndex(first, size);
this.next = this.calculateNewIndex(first, size);