[질문] non-static reference...


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :이홍락 1998년 11월 02일 13:53:34

자료구조 숙제로 polynomial 클래스를 만들었는데,


이런 에러가 나네요


non-static method add(poly, poly) cannot be referenced in the static context...


왜 이런 에러가 나는지 좀 알려주세요



소스도 여기 적습니다.


class poly {
double coef;
int exp;
poly link;


poly() {
link= null;
coef=(double)0;
exp=0;
}


poly(double coef_, int exp_){
link= null;
coef=coef_;
exp= exp_;
}


poly(double coef_, int exp_, poly node_) {
link= node_;
coef= coef_;
exp= exp_;
}


poly(poly node_) {
link= null;
coef= node_.get_coef();
exp= node_.get_exp();
}



void set_link(poly next) {
this.link= next;
}



poly get_link() {
return this.link;
}


void set_element(double coef_, int exp_) {
coef= coef_;
exp=exp_;
}


void set_element(double coef_, int exp_, poly link_) {
coef= coef_;
exp=exp_;
link= link_;
}

void set_element (poly item) {
coef= item.get_coef();
exp= item.get_exp();
link= item.get_link();
}


double get_coef() {
return coef;
}

void set_coef(double coef_) {
this.coef= coef_;
}


int get_exp() {
return exp;
}


void set_exp(int exp_) {
this.exp= exp_;
}



//assume that polynomial are well sorted......

public poly add(poly a, poly b) {
poly head= new poly();
poly c= head;
poly temp=null;
int a_exp, b_exp;
double a_coef, b_coef;
for (;;) {
a_coef= a.get_coef();
b_coef= b.get_coef();
a_exp= a.get_exp();
b_exp= b.get_exp();


if (a_exp>b_exp) {
c.set_element(a);
a=a.get_link();
}
else if (a_exp<b_exp) {
c.set_element(b);
b=b.get_link();


}
else if (a_coef+b_coef!=0) {
c.set_element(a_coef+b_coef, a_exp);
a=a.get_link();
b=b.get_link();
}


temp= new poly();
c.set_link(temp);
c=temp;


if (a==null && b==null) break;
if (a==null) {
while (b!=null) {
c.set_link(b);
b=b.get_link();
temp= new poly();
c.set_link(temp);
c=temp;
}
break;
}
else if (b==null) {
while (a!=null) {
c.set_link(a);
a=a.get_link();
temp= new poly();
c.set_link(temp);
c=temp;
}
break;
}
}
return head;
}


poly sub(poly a, poly b) {
poly c= b.scalar(-1);
return add(a, c);
}

poly mult (poly a , poly b) {
poly c= new poly();
poly head= c;
poly b_head=b;
poly temp;
while (a!=null) {
b=b_head;
while (b!=null) {
c.set_element(b.get_coef()*a.get_coef(), a.get_exp()+b.get_exp());
temp= new poly();
c.set_link(temp);
c=temp;
b=b.get_link();
}
a=a.get_link();
}
return head;
}

poly div( poly a, poly b) {
poly c= new poly();
poly head= c;
poly quot=a;
poly temp;


while (quot !=null) {
int diff= quot.get_exp()- b.get_exp();
double coef_div= quot.get_coef() / b.get_coef();
if (diff>=0) {
quot= sub( quot, b.exp_add(diff).scalar(coef_div));
}
c.set_element(coef_div, diff);
temp= new poly();
c.set_link(temp);
c=temp;
}
return head;
}



poly mod(poly a, poly b) {
poly quot=a;
poly temp;


while (quot !=null) {
int diff= quot.get_exp()- b.get_exp();
double coef_div= quot.get_coef() / b.get_coef();
if (diff>=0) {
quot= sub( quot, b.exp_add(diff).scalar(coef_div));
}
}
return quot;
}








void print() {
poly a=this;
while (a!=null){
System.out.println(a.coef + " " + a.exp );
a=a.get_link();
}
}

poly scalar(double k) {
poly a=this;
poly b= new poly();
poly head= b;
poly temp;
while (a!=null){
b.set_element(a.get_coef()*k, a.get_exp());
a=a.get_link();
temp= new poly ();
b.set_link(temp);
b=temp;

}
return b;
}

poly exp_add(int k) {
poly a=this;
poly b= new poly();
poly head= b;
poly temp;
while (a!=null){
b.set_element(a.get_coef(), a.get_exp()+k);
a=a.get_link();
temp= new poly ();
b.set_link(temp);
b=temp;


}
return b;
}



public static void main(String args[]) {
poly poly1= new poly(3.0,2,new poly(1.0,1,new poly(1.0,0)));


poly1.print();


add(poly1, poly1).print();


}



}












다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]