0

我需要编写一个通过修改当前多项式来求导的方法。我可以写一个与返回类型一起工作的。这是代码:

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;
}

如何使用代码的上半部分将其变为 void:

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;
        }
    }
}
4

1 回答 1

1

假设您通过说来区分,那么您可以尝试与myPolyList.differentiate();交换。唯一的问题是,现在这不太行得通,因为你无法从 polyList 中获取第一个 poly。return res;this.poly = res.poly;polyprivate

编辑:有关如何设置程序的更多信息将帮助我给出更具体的答案。

于 2013-03-19T04:52:29.870 回答