ZAD4 #33

Closed
s426182 wants to merge 18 commits from (deleted):ZAD4 into master
Showing only changes of commit 14bd8e6827 - Show all commits

View File

@ -97,5 +97,42 @@ 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;
}
}