I would like to know how it working. Here is the question.. isnt it put the method Iterable positions();?
Please help me to figure it out.

Suppose we want to extend the PositionalList ADT with a method, indexOf(p), that returns the current index of the element stored at position p. Write this method using only other methods of the PositionalList interface (not details of our LinkedPositionalList implementation). Write the necessary code to test the method. Hint: Count the steps while traversing the list until encountering position p

public interface PositionalList<E> extends Iterable<E> {

int size();

boolean isEmpty();

Position<E> first();

Position<E> last();

Position<E> before(Position<E> p) throws IllegalArgumentException;

Position<E> after(Position<E> p) throws IllegalArgumentException;

Position<E> addFirst(E e);

Position<E> addLast(E e);

Position<E> addBefore(Position<E> p, E e)
throws IllegalArgumentException;
Position<E> addAfter(Position<E> p, E e)
throws IllegalArgumentException;

E set(Position<E> p, E e) throws IllegalArgumentException;

E remove(Position<E> p) throws IllegalArgumentException;

Iterator<E> iterator();
Iterable<Position<E>> positions();

}

Hint: Count the steps while traversing the list until encountering position p

isnt it put the method Iterable positions();?

Yes. Simply use positions() to loop through the elements incrementing an index and and test each until you find the one you want. Then return its index.

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.