MaxDegree를 이용한 Polynomial
다항식 덧셈하기 소스 다항식의 표현에는 3가지 정도가 존재한다고 책에 써있다. 1번 . #define MaxDegree 10000 // 배열 coef의 가장 최대값을 설정 class Polynomial{ public: Polynomial(int d=0); Polynomial Add(Polynomial p); void initialize(); void Print(); private: int degree; int coef[MaxDegree+1]; }; 위 소스와 다항식의 지수를 MAxDegree로 몽땅 잡아놓고 쓰는 방법 매우 불필요한 공간이 낭비된다. 2번. private: int degree; float* coef; 요렇게 하고 생성자 부분에서 coef = new float[degree+1] degree..
전공/자료구조
2009. 7. 16. 05:49