2013-03-19 3 views
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; 
} 

: 다음은 코드의 myPolyList.differentiate(); 말하여 차별화를 호출한다고 가정

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

답변

1

을, 당신은 this.poly = res.poly;return res; 교환 시도 할 수 있습니다 . 유일한 catch는 지금 당장입니다. polyprivate이고 폴리리스트에서 첫 번째 폴리곤을 얻을 수있는 방법이 없습니다.

편집 : 프로그램 설정 방법에 대한 정보를 좀 더 구체적으로 알려줍니다.