I am trying to access the edited poly node when making and checking combining.degree, however I get a NullPointerException, how can I fix this? I want to use the poly that was edited in the while loop instead of the poly made outside of the while loop that was made null. This is a
public static Node multiply(Node poly1, Node poly2) {
Node poly3=poly1;
Node poly4=poly2;
Node poly=null;
while (poly3!=null)
{
while(poly4!=null)
{
float x;
int y;
x=poly3.term.coeff*poly4.term.coeff;
y=poly3.term.degree*poly4.term.degree;
poly=new Node(x,y,poly);
poly4=poly4.next;
}
poly4=poly2;
poly3=poly3.next;
}
Node finalpoly=null;
int i=poly.term.degree;
float csum=0;
Node combining = poly;
while (i>=combining.term.degree)
{
while (combining!=null)
{
if (i==combining.term.degree)
{
csum+=combining.term.coeff;
}
combining=combining.next;
}
if (csum!=0)
{
finalpoly = new Node(csum, i, finalpoly);
}
i--;
}