# Thread: Creating polynomial using linked lists

1. Member
Join Date
Mar 2011
Posts
16
Rep Power
0

## Creating polynomial using linked lists

public class Polynomial {
/* Constructs a new polynomial of degree zero */
public Polynomial() {
}

/* Returns an integer representing the coefficient
* of the x^power term
*/
int getCoefficients(int power) {
}

/* Sets the coefficient of the x^power term to coef. */
void setCoefficients(int coef, int power) {
}

/* Returns the String representation of the polynomial.
* For example, a polynomial can be represented as either
* 3 * x^2 + 2 * x + 1 or
* 3x^2 + 2x + 1
* Any term whose coefficient is zero should not appear
* in the string unless the polynomial has only a single
* constant term of zero.
*/
public String toString() {
}

/* Evaluates the polynomial for the value x and returns
* the result p(x).
*/
double evaluate(double x) {
}

/* Add to this polynomial the polynomial "other" and
* return the resulting polynomial.
*/
Polynomial add(Polynomial other) {
}
}
Any idea

2. Originally Posted by joe98
Any idea
Yeah, I have an idea that I will go home and start my weekend. WOOHOO!

3. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
ok junky :P

4. That was my subtle way to tell you to ask a better question.

5. My idea:
I think so should at least try to make one method, not just give us prototypes.
Maybe should should start with the constructor, then evaluate, that seems fairly simple.

Also drop the s from getCoefficients and setCoefficients, you do only set one coefficient per call.

And if you want toString() to be real nice, substitute ↑ for ^, or better yet, use superscript (⁰¹²³⁴⁵⁶⁷⁸⁹).

6. When you have done that implement toString(), and add() by using getCoefficients() and setCoefficients(), and that leaves you with getCoefficients() and setCoefficients().

Also, if all possible I would suggest not using linked lists, but two arrays (or look into hash tables/maps, that is even better and simpler), but I assume this is some kind of homework?
Last edited by Hibernate; 08-05-2011 at 09:44 AM.

7. Cross posted at Polynomial java file - Java

8. Member
Join Date
Aug 2011
Posts
95
Rep Power
0
Originally Posted by Hibernate
And if you want toString() to be real nice, substitute ↑ for ^, or better yet, use superscript (⁰¹²³⁴⁵⁶⁷⁸⁹).
Nifty! (I do keep forgetting that we're working with UNICODE here. ;-)

9. It is okay to call it Unicode, but please don't hold down shift while pressing the six last keys.
And you can [and should in some cases] use it in variable names [&c].

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•