0
이 프로그램은 다항식을 다루고 있습니다. 내 임무의 마지막 부분에 문제가있다. 나는 다항식을도 단위로 정렬해야하고 다항식에 이중 차수가있는 경우 다항식을 줄일 수 있어야합니다. 아래에 작성한 코드에는 두 기능에 대한 세그멘테이션 오류가 있습니다. 내 void reduce(poly &p1)
에서 내 오류는 zc= zc->next
에서 발생합니다. 이러한 기능을 완료하기 위해 접근하는 다른 방법이 있습니까? 플러스 내 다항식링크 목록 삽입 정렬 및 다항식 감소 C++
class Poly{
private :
struct term{
double coef ;
unsigned exp ;
term *next ;
} *term_t ;
public :
Poly() ;
void insert (float c, int e) ;
void isort(Poly &p1);
void reduce (Poly &p1);
~Poly() ;
} ;
void Poly :: isort (Poly & p1){
term *z;
term * zc;
term *c;
if (term_t == NULL && p1.term_t == NULL)
return ;
while (p1.term_t != NULL){
c=p1.term_t;
p1.term_t = p1.term_t->next;
while (p1.term_t!=NULL && c->exp > zc->exp){
z->coef = c->coef;
z->exp=c->exp;
c=c->next;
}
z.printPoly();
zc->exp = z->exp;
z=z->next;
//c=c->next;
}
}
void Poly :: reduce (Poly & p1){
term *z ;
if (term_t == NULL && p1.term_t == NULL)
return ;
term *temp1;
temp1 = p1.term_t ;
while (temp1 != NULL){
if (term_t == NULL){
term_t = new term ;
z = term_t ;
}
else{
z -> next = new term ;
z = z -> next ;
}
if (temp1 -> exp == z->exp)
temp1->coef= temp1-> coef + z->coef;
z->coef = temp1 -> coef;
z->exp = temp1->exp;
temp1=temp1->next;
}
while (temp1 != NULL){
if (term_t == NULL){
term_t = new term ;
z = term_t ;
}
else{
z -> next = new term ;
z = z -> next ;
}
z -> coef = temp1 -> coef ;
z -> exp = temp1 -> exp ;
temp1 = temp1 -> next ;
}
z -> next = NULL ;
}
을 사용할 수 있지만, 당신은 또한'[숙제를 사용해야합니다 ] 태그. –