# Polynomial multiplication

• 03-28-2012, 03:24 AM
itsmyday7
Polynomial multiplication
Hey guys, I am stuck in making a polynomial multiplication... please help me out.... how to multiply two polynomials...your little help would be much appreciated

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dataStructures;

import java.util.Scanner;

class PolynomialNode{
int power;
int coefficient;
PolynomialNode next;

public PolynomialNode(int coefficient, int power){
this.coefficient = coefficient;
this.power = power;
next = null;
}
public int getX()
{
return this.power;
}
public int getA()
{
return this.coefficient;
}

public String toString(){
return ""+ coefficient + "*X^" + power;
}

public static PolynomialNode listSearch(PolynomialNode head, int target_power)
{
PolynomialNode cursor;
if (head == null) return null;
for (cursor = head; cursor.next != null; cursor = cursor.next)
if ((cursor.power >= target_power)&&(cursor.next.power < target_power))
return cursor;

return cursor;
}

}

class PolynomialEquation{

public PolynomialEquation(){
}
{
}

public void add (int coefficient, int power){
{

{
PolynomialNode newN=new PolynomialNode(coefficient,power);
}
}
PolynomialNode newNode = new PolynomialNode(coefficient,power);

if(pos == null) head = newNode;
else if(pos.power == power) pos.coefficient+=coefficient;
else {
PolynomialNode temp = pos.next;
pos.next = newNode;
newNode.next = temp;
}
}
public static PolynomialEquation Addpoly(PolynomialEquation one, PolynomialEquation two)
{
PolynomialEquation result=one;
while(true)
{
if(temp.next==null)return result;
temp=temp.next;
}

}

public static PolynomialEquation MultiplyPolyByConstant (PolynomialEquation value1, int value2)
{
PolynomialEquation result=new PolynomialEquation();
while(true)
{
if(temp.next==null)return result;
temp=temp.next;
}
}

public void printEquation(){
for(PolynomialNode n = head; n != null; n = n.next){
System.out.println(n);
}
}

}

public class ITC322Assignment1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
PolynomialEquation pe = new PolynomialEquation();

Scanner input = new Scanner(System.in);

int m = input.nextInt();
int n = input.nextInt();
int o = input.nextInt();
int p = input.nextInt();
int q = input.nextInt();
int r = input.nextInt();
int s = input.nextInt();
int t = input.nextInt();

System.out.println("Printing PE");
pe.printEquation();

PolynomialEquation pe1 = new PolynomialEquation();
System.out.println("Printing PE1: ");
pe1.printEquation();

PolynomialEquation multiply = PolynomialEquation.MultiplyPolyByConstant(pe1, 2);
System.out.println("\nMultiplication by Constant 2: ");
multiply.printEquation();

}
}
• 03-28-2012, 08:35 AM
JosAH
Re: Polynomial multiplication