Discussion:
regarding toString code
(too old to reply)
Ennis
2004-11-06 07:18:01 UTC
Permalink
public String toString() {
if (poly.getHead() == null) {
return "0.0";
}

Why is the check for if head is equal to null? doesnt the project say
that every polynomial must consist of atleast one term...so the zero
polynomial will have the term 0x^0...so shouldnt the check be

if ((poly.getHead().getDatum() == 0)&&(poly.getHead().getNext() == null)){
return "0.0";
}
Igor Ivkovic
2004-11-07 20:43:38 UTC
Permalink
The code provided on the course web site is just an example of how to
implement this method and you may choose to implement it differently.

As for your question, we are checking if the head is null to improve
robustness of our code and to ensure that it does not fail under
unexpected conditions, which in this case is that there are no elements
left in the underlying linked list data structure.

Igor
Post by Ennis
public String toString() {
if (poly.getHead() == null) {
return "0.0";
}
Why is the check for if head is equal to null? doesnt the project say
that every polynomial must consist of atleast one term...so the zero
polynomial will have the term 0x^0...so shouldnt the check be
if ((poly.getHead().getDatum() == 0)&&(poly.getHead().getNext() == null)){
return "0.0";
}
Loading...