0
我需要編寫一個方法,它通過修改當前多項式來導出微分。我可以寫一個適用於返回類型的函數。下面的代碼:多項式的導數(void版本)
public PolynomialSortedList differentiate() {
PolynomialSortedList res = new PolynomialSortedList();
for(PolyNode tmp = poly; tmp != null; tmp = tmp.next)
{
if(tmp.exp != 0)
res.addTerm(tmp.coef * tmp.exp, tmp.exp - 1);
}
return res;
}
我如何使用代碼的這個上部變成無效:
public class PolynomialSortedList implements Polynomial {
private PolyNode poly;
private double TOLERANCE = 0.00000001;
public PolynomialSortedList() {
poly = null;
}
private static class PolyNode {
int coef;
int exp;
PolyNode next;
PolyNode(int coef, int exp,PolyNode next) {
this.coef = coef;
this.exp = exp;
this.next = next;
}
}
}