multiply polynomials

This commit is contained in:
Krystian Madra 2018-06-28 00:30:33 +02:00
parent bf3dacbbc6
commit 14bd8e6827

View File

@ -98,4 +98,41 @@ public class Main {
return result;
}
public static LinkedList<Integer> shiftList(LinkedList<Integer> p, int places){
LinkedList<Integer> result = new LinkedList<Integer>(p);
if(places == 0) {
return result;
}
for(; places>0; places--) {
result.addFirst(0);
}
return result;
}
public static LinkedList<Integer> polynomialsMultiplication(LinkedList<Integer> p1, LinkedList<Integer> p2){
// suma dlugosci
int amount = p1.size() + p2.size();
// nowy wielomian bedzie dlugosci sumy poteg wyrazow wiodacych obu tablic -1
LinkedList<Integer> result = new LinkedList<Integer>();
for(int i=0;i<amount-1;i++) {
result.add(0);
}
// mnozenie
for(int i=0; i<p1.size(); i++) {
for(int j=0; j<p2.size(); j++) {
result.set(i+j, (result.get(i+j) + p1.get(i) * p2.get(j)));
}
}
return result;
}
}