Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node polyRet = null;
- float Coef3 = 0;
- boolean flag = false;
- Node node1 = poly1;
- Node node2 = poly2;
- while(poly1 != null && poly2 != null) {
- if(poly1.term.degree == poly2.term.degree) {
- Coef3 = poly1.term.coeff + poly2.term.coeff;
- }
- else {
- // display both of them
- flag = true;
- }
- if(polyRet == null) {
- polyRet = new Node(Coef3, poly1.term.degree, poly1);
- }
- else {
- if (!flag) {
- polyRet.next.term = new Term(Coef3, poly1.term.degree);
- }
- else {
- polyRet.next.term = new Term(poly2.term.coeff, poly2.term.degree);
- //new Node(poly1.term.coeff, poly1.term.degree, null);
- //polyRet.next.next.term = new Term(poly1.term.coeff, poly1.term.degree);
- }
- }
- poly1 = poly1.next;
- poly2 = poly2.next;
- }
- return polyRet;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement