All pastes #956053 Raw Edit

CircularQueueIterator

public java v1 · immutable
#956053 ·published 2008-03-25 00:22 UTC
rendered paste body
package org.lurey.cs2b.assignments.circularLinkedList;import java.util.Iterator;/** * CircularQueueIterator, as described in Assignment #8 * - Keeps a pointer * - Has methods hasNext() and next() *  * Implements java.util.Iterator for Standardization *  * @author Matan Lurey */public class CircularQueueIterator implements Iterator {    private CircularQueue cQ;    private int pointer = -1;        /**     * Constructor for the Iterator     * Wraps around a CircularQueue     *      * @param cQ     */    public CircularQueueIterator(CircularQueue cQ){        this.cQ = cQ;    }        /**     * Returns if there is remaining items in the Circular Queue     * @return     */    public boolean hasNext(){        return pointer < cQ.size();    }        /**     * Returns the next item, or null if there are no more items     * @return     */    public Object next(){        if (hasNext()){            pointer++;            return cQ.get(pointer);        }                return null;    }        /**     * Removes the current item. Not implemented in this application.     */    public void remove(){        return;    }}