Can someone please help me go over these codes? There are no bugs in all except LinkedListBinary.java and I have no idea why. The lines that are causing me problems are:

/** Returns an iterator of the elements stored at the nodes */
  public Iterator<E> iterator() {
	   Iterable<Position<E>> positions = positions();
	   PositionList<E> elements = new NodePositionList<E>();
	   for (Position<E> pos: positions) 
	     elements.addLast(pos.element());
	    return elements.iterator();  // An iterator of elements
   }

The error is that I can only iterate from an array or an instance of java.lang.Iterable

I attached all the files, excluding the exception classes

Recommended Answers

All 3 Replies

I think it would help if you let the LinkedBinaryTree class implement Iterable<E>.
Then, you should be able to iterate in a for loop.

I found another way to do it. I deleted Iterable.java and Iterator.java and then imported java.util.Iterator

Great, good luck with the project!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.