Results 1 to 9 of 9
 08052011, 08:52 AM #1Member
 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
 08052011, 08:57 AM #2
 08052011, 09:10 AM #3Member
 Join Date
 Mar 2011
 Posts
 16
 Rep Power
 0
ok junky :P
 08052011, 09:13 AM #4
That was my subtle way to tell you to ask a better question.
 08052011, 09:39 AM #5
 Join Date
 Dec 2010
 Location
 Stockholm, Sweden
 Posts
 222
 Blog Entries
 9
 Rep Power
 10
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 (⁰¹²³⁴⁵⁶⁷⁸⁹).Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
 08052011, 09:41 AM #6
 Join Date
 Dec 2010
 Location
 Stockholm, Sweden
 Posts
 222
 Blog Entries
 9
 Rep Power
 10
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; 08052011 at 09:44 AM.
Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
 08052011, 03:17 PM #7
Cross posted at Polynomial java file  Java
 08052011, 04:03 PM #8Member
 Join Date
 Aug 2011
 Posts
 95
 Rep Power
 0
 08062011, 06:29 AM #9
 Join Date
 Dec 2010
 Location
 Stockholm, Sweden
 Posts
 222
 Blog Entries
 9
 Rep Power
 10
Similar Threads

singlie linked list polynomial addition
By fusi0n556 in forum New To JavaReplies: 0Last Post: 05242011, 10:07 AM 
Creating a node for polynomial linked list
By JavaGuy in forum New To JavaReplies: 8Last Post: 03172011, 09:27 PM 
Linked Lists
By Dee in forum New To JavaReplies: 18Last Post: 02022011, 04:14 AM 
Linked Lists
By vendetta in forum New To JavaReplies: 6Last Post: 01262010, 09:23 AM
Bookmarks