| | |
linked list polynomial help with add Term?
![]() |
•
•
Join Date: Feb 2009
Posts: 43
Reputation:
Solved Threads: 7
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: 43
Reputation:
Solved Threads: 7
0
#2 22 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 |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list loop looping map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt threads tree web websites windows





