| | |
linked list polynomial help with add Term?
![]() |
•
•
Join Date: Feb 2009
Posts: 37
Reputation:
Solved Threads: 6
I am currently building a Polynomial linked list.
Classes
Node, that has a Term and a Node next.
http://www.boomica.com/Node.java
Term with a coefficient and exponent.
http://www.boomica.com/Term.java
Polynomial
http://www.boomica.com/Polynomial.java
My Driver:
It's seems its messing up when I try to switch 3 + 3x(or 3x^1), it wont sort after.
I went through step by step with the Eclipse Debugger and couldnt find it.
Could anyone help me out, and tell me why it isnt sorting correctly and to share opinions on my Add method as do you think it is efficient?
Help is greatly appreciated! =)
Classes
Node, that has a Term and a Node next.
http://www.boomica.com/Node.java
Term with a coefficient and exponent.
http://www.boomica.com/Term.java
Polynomial
http://www.boomica.com/Polynomial.java
Java Syntax (Toggle Plain Text)
public void addTerm(Term nomial) { Node temp = first; Node toAdd; if(isEmpty() || (temp.getTerm().compareTo(nomial) <= 0)) { Node newFirst = new Node(nomial, first); first = newFirst; } else { while((temp.getTerm().compareTo(nomial) >= 0) && temp.getNext() != null) { temp = temp.getNext(); } if(temp.getNext() == null) { toAdd = new Node(nomial, null); temp.setNext(toAdd); } else { toAdd = new Node(nomial, temp.getNext()); temp.setNext(toAdd); } } }
My Driver:
Java Syntax (Toggle Plain Text)
package dsa.exam; public class PolynomialDriver { public static void main (String args[]) { Polynomial nomial = new Polynomial(); nomial.addTerm(new Term(3)); nomial.addTerm(new Term(2,7)); nomial.addTerm(new Term(3,6)); nomial.addTerm(new Term(3, 1)); nomial.addTerm(new Term(3, 8)); //nomial.addTerm(new Term(3,2)); //nomial.addTerm(new Term(3,5)); //double answer = one.evaluate(2) + two.evaluate(2) + three.evaluate(2) + four.evaluate(2) + five.evaluate(2); String s = nomial.printPolynomial(); System.out.println(s); } }
It's seems its messing up when I try to switch 3 + 3x(or 3x^1), it wont sort after.
I went through step by step with the Eclipse Debugger and couldnt find it.
Could anyone help me out, and tell me why it isnt sorting correctly and to share opinions on my Add method as do you think it is efficient?
Help is greatly appreciated! =)
•
•
Join Date: Feb 2009
Posts: 37
Reputation:
Solved Threads: 6
0
#2 18 Days Ago
Found another problem, seems this doesnt encounter for when I have the same terms.
I will need to probably set it up like
BUt I still cant figure out why it messes up the descending linked list when I add terms with exponent on 0.
I will need to probably set it up like
Java Syntax (Toggle Plain Text)
if(exponents match) { nomial = term.addition(term) //Addition in term class } Node toAdd(nomial.....etc)
BUt I still cant figure out why it messes up the descending linked list when I add terms with exponent on 0.
![]() |
Similar Threads
- Simple Linked List with user input (C)
- How to recursively find a value in a linked list (Java)
- Linked List and Dynamic Array Problem (C++)
- sort insert in a generic linked list (Java)
- Please Help - Linked List (C++)
- Linked List (C++)
- Linked List - Please help needed Urgently!!! (C++)
Other Threads in the Java Forum
- Previous Thread: Need Project Suggestion
- Next Thread: Building a simple Java web crawler
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update windows working





