## Question

P(x) = 5x¹⁰ + 9x⁷ -10

As a Collection of terms. A term contains the coefficient and the power of x. For example, you would store p(x) as

(5,10), (9,7), (-1,1) (-10,0)

Supply a method to perform addition, multiply, and print polynomials. Supply a constructor that makes a polynomial from a single term. For example, the polynomial p can be constructed as (keep in mind this is just a sample and feel free to make adjustments)

Polynomial p = new Polynomial (new Term (-10,0));

p.add(new Polynomial (new Term(-1,1)));

p.add(new Polynomial (new Term(9,7)));

p.add(new Polynomial (new Term(5,10)));

Then compute p(x) X p(x)

Polynomial q = p.multiply(p);

q.print();

Hint:

You can pick and choose any form of data type for this exercise. The key is the multiple and addition of polynomial. You can reuse any of the interface for this question. FYI, you will need to adjust the LLNode from the source code with one additional variable (say, info1 and info 2) to hold the coefficient and power number for each term. For the print out method, you can use the ^ to indicate the power of. For example, 5x10 would display as 5x^10

Please show a print out of the additional, multiplication and eventually print of the resultant polynomial.

2. Write a program that inserts 25 random integers from 0 to 100 in order into a linked list object. The program should sort the elements recursively, then sum up the elements and the floating point average of the elements.

Hint:

You are welcome to use any recursive sort to sort the elements. Also, print out your number before and after the sort, and display the sum and average. Use Generic <T> as part of your code.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class LinkedUnbndQueue<T> implements UnboundedQueueInterface<T> {protected LLNode<T> front; // reference to the front of this queue

protected LLNode<T> rear; // reference to the rear of this queue

private int size;

public LinkedUnbndQueue() {

front = null;

rear = null;

size = 0;

}

public void enqueue(T element) // Adds element to the rear of this queue.

{

LLNode<T> newNode = new LLNode<T>(element);

if (rear == null) {

front = newNode;

} else {

rear.setLink(newNode);

}

rear = newNode;

size++;

}

public T dequeue() // Throws QueueUnderflowException if this queue is empty;

// otherwise, removes front element from this queue and returns it.

{

if (isEmpty()) {

throw new QueueUnderflowException("Dequeue attempted on empty queue.");

} else {

T element;

element = front.getInfo();

front = front.getLink();

if (front == null) {

rear = null;

}

size--;

return element;

}

}

public boolean isEmpty() // Returns true if this queue is empty; otherwise, returns false.

{

if (front == null) {

return true;

} else {

return false;

}

}

public LinkedUnbndQueue<T> clone() {

LinkedUnbndQueue<T> luq = new LinkedUnbndQueue<>();

LLNode<T> n = front;

while (n != null) {

luq.enqueue(n.getInfo());

n = n.getLink();

}

return luq;

}

public int getSize() {

return size;

}

}...

By purchasing this solution you'll be able to access the following files:

Solution.zip.