Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Node polyRet = null;
  2. float Coef3 = 0;
  3. boolean flag = false;
  4.  
  5. Node node1 = poly1;
  6. Node node2 = poly2;
  7.  
  8. while(poly1 != null && poly2 != null) {
  9.  
  10. if(poly1.term.degree == poly2.term.degree) {
  11. Coef3 = poly1.term.coeff + poly2.term.coeff;
  12.  
  13. }
  14. else {
  15. // display both of them
  16. flag = true;
  17. }
  18.  
  19. if(polyRet == null) {
  20. polyRet = new Node(Coef3, poly1.term.degree, poly1);
  21. }
  22. else {
  23. if (!flag) {
  24. polyRet.next.term = new Term(Coef3, poly1.term.degree);
  25.  
  26. }
  27. else {
  28. polyRet.next.term = new Term(poly2.term.coeff, poly2.term.degree);
  29. //new Node(poly1.term.coeff, poly1.term.degree, null);
  30. //polyRet.next.next.term = new Term(poly1.term.coeff, poly1.term.degree);
  31. }
  32. }
  33. poly1 = poly1.next;
  34. poly2 = poly2.next;
  35.  
  36. }
  37.  
  38. return polyRet;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement