#include <stdio.h>
#define Max_Degree 101

typedef struct{
    int degree;
    float coef[Max_Degree];
}polynomial;

// 연결리스트 구조체만들기
typedef struct list{
    float coef; //계수
    int expon;  //지수
    struct list *link; //다음항의 주소
} list;

// d=a+b, where a,b,, and d are polynomial

int compare(x,y){
    if(x<y) return -1;
    else if (x==y) return 0;
    else return 1;
}

// A(x) = 2x¹⁰⁰⁰ + 1
// B(x) = x⁴ + 10x³ + 3x² + 1
// D(x) = A(x) + B(x) = 2x¹⁰⁰⁰ + x⁴ + 10x³ + 3x² + 2
/* d = a+b, where a, b, and d are polynomials */
// 빈 다항식 생성
d=Zero()

//Attach

// isZero 다항식 a가 비어있는지 검사
// Lead_Exp(): 현재 다항식 a에서 가장 앞에 있는 항, 즉 최고차항의 지수
// Coef()는 계수를 가져온다
// Attach(다항식, 계수, 지수) : 결과 다항식 d에 새로운 항을 붙인다
// Remove(a, Lead_Exp(a)): 처리되었으니 해당항을 제거하고 다음으로 넘어간다
while(!isZero(a) && I isZero(b)) do {
    switch compare(lead Exp(a), lead_Exp(b)){ //Lead_Exp(a): a,b의 최고차항의 지수비교
        case -1: 
            d=Attach(d, Coef(b, Lead_Exp(b)),Lead_Exp(b));//a의 현재항을 결과 다항식 d에 붙여라
            b=Remove(b,Lead_Exp(b)) //b의 지수,계수를 삭제
        case 0:
            sum = Coef(a,Lead_Exp(a))+Coef(b,Lead_Exp(b));//a의지수,계수+b의지수,계수
            if(sum){
                Attach(d,sum,Lead_Exp(a)); //
                a=Remove(a,Lead_Exp(a));
                b=Remove(b,Lead_Exp(b));                
            }
            break;
        case 1:
            d=Attach(d,Coef(a,Lead_Exp(a))),Lead_Exp(a)));
            a=Remove(a,Lead_Exp(a));        
    }
    
}

int main() {
    printf("Hello world!\n");
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: