Вопрос

I have started studying trees in java. I have found an interface for tree that is in code below:

    public interface Tree<E> {

    public int size();
    public boolean isEmpty();
    public Iterator<E> iterator();
    public Iterable<Position<E>> positions();
    public E replace(Position<E> v, E e)
    public Position<E> root();
    public Position<E> parent(Position<E> v);
    public Iterable<Position<E>> children(Position<E> v);
    public boolean islnternal(Position<E> v);
    public boolean isExternal(Position<E> v);
    public boolean isRoot(Position<E> v);
    }

when I write this cod with these imports:

    import java.util.Iterator;
    import javax.swing.text.Position;

I face with this Error : type position does not take parameter

I can't understand what should I do to have this tree interface to be generic. can any one please help me?? thanks in advance for your attention

Это было полезно?

Решение 2

You have the wrong Position import. I don't think it's the javax.swing.text.Position that you need. You are mistaking it for another Position. Where did you find this Tree interface?

Другие советы

From the book Data Structures & Algorithms (5th Edition) by Michael T. Goodrich and Roberto Tamassia - from which this question was derived, the Position class with generics referenced is a custom interface defined earlier in the book on page 250. In the interest of completeness for those who perhaps don't have the book the code is very short and simple as follows:

public interface Position<E> {
  /** Return the element stored at this position */
  E element();
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top