1

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

4
  • Position is not defined to be generic. Commented Dec 4, 2013 at 17:29
  • then how should I make generic interface for tree? Commented Dec 4, 2013 at 17:32
  • it could be that Position is declared generic in some other package and you have used the wrong import statement where Position is not defined to be generic. Commented Dec 4, 2013 at 17:36
  • from your text book "The positions in a tree are its nodes, and neighboring positions satisfy the parent-child relationships that define a valid tree." So, the positions are nodes of the tree. Read the complete text :) Commented Dec 4, 2013 at 17:48

2 Answers 2

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

0

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?

2 Comments

in a book named Data Structures & Algorithms in java from Michael T. Goodrich
@TTS Well you need to find out in which package do you find the correct Position. You've missed something in the book.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.