[Áú¹®] 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:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]