Page 1 of 1

## 2 Replies - 276 Views - Last Post: 29 October 2017 - 10:58 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=407244&amp;s=7ad3c36d0f0e93f28b9ab6a3d21ff7d2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 aemaeth

Reputation: 0
• Posts: 39
• Joined: 10-February 17

Posted 29 October 2017 - 12:56 AM

I'm trying to write an equals method for a polynomial linked list that holds 3 terms (coefficient, exponent, and link). I keep getting it saying "false" or "True" when it should be the other way around, this is what I have:

```public boolean equals (Object obj)
{
if(obj instanceof Polynomial)
{
Polynomial candidate = (Polynomial) obj;

while(cursor1 != null)
{
while(cursor2 != null)
{
if(!((cursor1.coefficient == cursor2.coefficient) || (cursor1.exponent==cursor2.exponent)))
{
return false;
}
}
}
return true;
}
return false;
}
```

I'm basically testing it in the main method with a simple polynomial like p1 = 7x^7 + 6 and p2 = 6x^7 + 6 and it should be false but reads true and blah blah blah

I've tried editing it and writing it like 30 other ways (i.e. using while ((cursor1 != null) && (cursor 2 != null))) etc but to no avail

Is This A Good Question/Topic? 0

## Replies To: linked list polynomial equals.method

### #2 g00se

• D.I.C Lover

Reputation: 3503
• Posts: 15,839
• Joined: 20-September 08

## Re: linked list polynomial equals.method

Posted 29 October 2017 - 04:45 AM

Well, i'll scramble things a little and say i think (i don't know your class - you haven't helped by showing out-of-context code) it's not correct - even if it 'worked' Why? Because, if it 'worked' it would return true if one list were a truncated form of the other. Try again and count the nodes.

### #3 aemaeth

Reputation: 0
• Posts: 39
• Joined: 10-February 17

## Re: linked list polynomial equals.method

Posted 29 October 2017 - 10:58 AM

This is a data structures Java class.

I have also been testing same size polynomials!