Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class PolynomialLinkedlist{ private static class PNode{ private int coe; private int exp; private PNode next; public PNode(int c, int e){ this(c, e, null); } public

image text in transcribed
class PolynomialLinkedlist{ private static class PNode{ private int coe; private int exp; private PNode next; public PNode(int c, int e){ this(c, e, null); } public PNode(int c, int e, PNode n){ coe = c; exp = e; next = n; } public void setCoe(int c){ coe = c;} public void setExp(int e){ exp = e;} public void setNext(PNode n){ next = n;} public int getCoe(){ return coe;} public int getExp(){ return exp;} public PNode getNext(){ return next;} } private PNode first; private PNode last; public PolynomialLinkedlist(){ first = last = null; } public PolynomialLinkedlist(int c, int e){ PNode tempn = new PNode(c, e); first = last = tempn; } public void print(){ if (first == null){ System.out.println(); return; } PNode temp = first; String ans = ""; while (temp != null){ if (temp.getCoe() > 0) { if (temp != first) ans = ans + " + "; ans = ans + temp.getCoe(); } else if (temp.getCoe() out.println(ans); } }
Implement Polynomial Linked List add method which adds two polynomials in standard form and returns sum polynomial which also has to be in standard form. Rewrite the instance method that takes a second Polynomial Linked List, and then adds all terms in the caller Polynomial and all terms in the second Polynomial Linked List together into another sum Polynomial. Both caller and parameter Polynomials are expected to be in standard form, the method should return the sum Polynomial also in standard form. A standard form polynomial has no duplicate terms (each term's exponent is unique) and the exponent is in descending order. Implement Polynomial Linked List add method which adds two polynomials in standard form and returns sum polynomial which also has to be in standard form. Rewrite the instance method that takes a second Polynomial Linked List, and then adds all terms in the caller Polynomial and all terms in the second Polynomial Linked List together into another sum Polynomial. Both caller and parameter Polynomials are expected to be in standard form, the method should return the sum Polynomial also in standard form. A standard form polynomial has no duplicate terms (each term's exponent is unique) and the exponent is in descending order

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions