Something feels wrong about both classes.

LinkedLists like other collections tend to favour non-specific datatypes. The Node class you have here is designed specifically for the polynomial.

The polynomial itself is simply a collection of Term. Since you have been given an insert method, that would indicate that this is to be developed from scratch instead of by using a builtin collection, which now means your Node should probably just be labeled as your Term. So you now have a Polynomial pseudocollection of type Term.

I don't see anything wrong with the insert method as defined specifically for the polynomial.

As for the Term class, I'm not sure what you need to do with it either. Given that this is a custom list, my perception of a polynomial is simply that it is a collection of Term (or more accurately, I'd call it a collection of ITerm since they can be either constant or variable). If you were to use a builtin collection, it would be tremendously easier (but I think the creation is the actual assignment :/)

How I perceive it:

PHP Code:

```
public interface ITerm
```

{

public final Comparator<ITerm> SORT_BY_EXP_DESC = new Comparator<ITerm>()

{

@Override

public int compare(ITerm t1, ITerm t2)

{

return t2.getExponent() - t1.getExponent();

}

};

public int getExponent();

}

public class Term implements ITerm

{

private int coefficient, exponent;

public Term()

{

this(0, 0);

}

public Term(int coefficient, int exponent)

{

this.coefficient = coefficient;

this.exponent = exponent;

}

public String toString()

{

return "Term[coefficient=" + this.coefficient + ", exponent=" + this.exponent + "]";

}

@Override

public int getExponent()

{

return this.exponent;

}

public static void main(String[] argv)

{

java.util.PriorityQueue<ITerm> pq = new java.util.PriorityQueue<ITerm>(10, ITerm.SORT_BY_EXP_DESC);

pq.add(new Term(5, 2));

pq.add(new Term(5, 7));

pq.add(new Term(5, 5));

ITerm tCurrent = pq.poll();

while (tCurrent != null)

{

System.out.println(tCurrent);

tCurrent = pq.poll();

}

}

}

Unfortunately with the Java PriorityQueue, the only time you are guaranteed the order specified is during the pq.poll(). I just ran a few tests and found that neither a print of it, nor an iteration of it provided the proper ordering. Checking the api confirmed that this is normal behaviour in a priority queue for java. You can however sort them by converting to an array instead (according to the API).