Help with custom iterator
<p>I'm having trouble with my custom iterator...it seems that the <code>next()</code> method is not working.</p>

<p>I think my constructor is not working...and I got this error message: java.lang.ArithmeticException: / by zero</p>

<pre><code>import java.util.Iterator;

public class RandomBag &lt;Item&gt; implements Iterable&lt;Item&gt;
{
  private Node first;
  private int N;
  private int k=0;

  private class Node
  {
    Item item;
    Node next;
  }

  public void add(Item item)
  {
    Node oldfirst = first;
    first = new Node();
    first.item = item;
    first.next = oldfirst;
    N++;
  }

  public boolean isEmpty()
  {
    return first == null;
  }

  public int size()
  {
    return N;
  }

  public Iterator&lt;Item&gt; iterator()
  {
    return new RandomIterator();
  }

  private class RandomIterator implements Iterator&lt;Item&gt;
  {    
    Item[] a = (Item[]) new Object [N];

    public RandomIterator()
    {
      int counter = 0;

      //put items in the array
      for (Node x=first; x!=null; x=x.next)
      {
        a[counter] = x.item;
        counter++;
      }

      //randomize the items in the array
      for (int i=0; i&lt;size(); i++)
      {
        int randomIndex = StdRandom.uniform(i, size());
        Item item = a[randomIndex];
        a[randomIndex] = a[i];
        a[i] = item;
      }
    }

    public void remove() {}

    public boolean hasNext()
    {
      return k!=N;
    }

    public Item next()
    {
      Item item = a[k % a.length];
      k++;
      return item;
    }
  }
  public static void main(String[] args)
  {
    RandomBag&lt;Double&gt; numbers = new RandomBag&lt;Double&gt;();
    Iterator iter = numbers.iterator();

    numbers.add(1.0);
    numbers.add(4.0);
    numbers.add(3.0);
    numbers.add(5.0);

    StdOut.println(iter.next());
    StdOut.println(iter.next());
    StdOut.println(iter.next());
    StdOut.println(iter.next());
  }
}
</code></pre>
