public Iterator<ElementType> iterator() {
        return new Iterator<ElementType>() {
            int idx = getIdx;
            int N = size;

            public boolean hasNext() {
                return N > 0;
            }

            public ElementType next() {
                ElementType x = (ElementType) elements[idx];
                idx = (idx + 1) % elements.length;
                N--;
                return x;
            }

            public void remove() {
                throw new UnsupportedOperationException("remove");
            }
        };
    }
public Iterator < ElementType > iterator ( ) { return new Iterator < ElementType > ( ) { int idx = getIdx ; int N = size ; public boolean hasNext ( ) { return N > 0 ; } public ElementType next ( ) { ElementType x = ( ElementType ) elements [ idx ] ; idx = ( idx + 1 ) % elements . length ; N -- ; return x ; } public void remove ( ) { throw new UnsupportedOperationException ( "remove" ) ; } } ; }
Returns an iterator intended usage in a foreach loop
@return an iterator that iterates over all elements in the queue