ZAD4 #33

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

View File

@ -134,5 +134,34 @@ public class Main {
}
return result;
}
}
public static LinkedList<Integer> substractPolynomials(LinkedList<Integer> p1, LinkedList<Integer> p2){
LinkedList<Integer> result = new LinkedList<Integer>();
LinkedList<Integer> p2Copy = new LinkedList<Integer>();
for(int i=0; i<p2.size(); i++) {
p2Copy.add(p2.get(i));
}
while(!p2Copy.isEmpty()) {
result.add(p1.poll() - p2Copy.poll());
}
while(!p1.isEmpty()) {
result.add(p1.poll());
}
while(result.getLast() == 0) {
if(result.size()>1) {
result.removeLast();
}
else break;
}
return result;
}
}