|
안녕하세요 만해입니다.
헐헐~
넘 오래된거라서요
잘 기억이 안나는데요
우선 에러만 잡아 봤습니다.
//---------------------------------------------------------------------------
#include <stdio.h>
#include <alloc.h>
typedef struct polyNode *polyPtr;
typedef struct{
int coef;
int exp;
polyPtr link;
}polyNode;
polyPtr d,a,b;
//---------------------------------------------------------------------------
polyNode* padd(polyNode* a, polyNode* b);
void attach(int coeff, int expo, polyNode *ptr);
int compare(int a , int b);
//---------------------------------------------------------------------------
int compare(int a, int b)
{
if ( a > b )
return 1;
else if ( a== b )
return 0;
else
return -1;
}
//---------------------------------------------------------------------------
void main()
{
polyNode* Root;
polyNode a,b,c;
a.coef = 2;
a.exp = 1;
b.coef = 2;
b.coef = 2;
a.link = &b;
b.link = &c;
c.link = NULL;
attach(2, 3, &c);
Root->link = a.link ;
Root = padd(&a,&b);
for ( ; Root ; Root = Root->link )
printf("%d %d",Root->coef,Root->exp);
}
//---------------------------------------------------------------------------
polyNode* padd(polyNode* a, polyNode* b)
{
polyNode* temp;
polyNode* temp1;
polyNode* temp2;
int sum;
temp2 = (polyNode*)malloc(sizeof(polyNode));
//if (IS_FULL(temp2)) return;
temp1 = temp2;
while (a && b)
switch (compare(a->exp , b->exp))
{
case -1 :
attach(b->coef, b->exp, &temp2);
b = b->link;
break;
case 0 :
sum = a->coef + b->coef;
if(sum)
attach(sum, a->exp, &temp2);
a = a->link;
b = b->link;
break;
case 1 :
attach(a->coef, a->exp, &temp2);
a = a->link;
break;
}
for (;a;a = a->link) attach(a->coef, a->exp, &temp2);
for (;b;b = b->link) attach(b->coef, b->exp, &temp2);
temp2->link = NULL;
temp = temp1;
temp1 = temp1->link;
free(temp);
return temp1;
}
//---------------------------------------------------------------------------
void attach(int coeff, int expo, polyNode *ptr)
{
polyNode* temp;
temp = (polyPtr)malloc(sizeof(polyNode));
// if (IS_FULL(temp)) return;
temp->coef = coeff;
temp->exp = expo;
ptr->link = temp;
ptr = temp;
}
//---------------------------------------------------------------------------
그런데 별 도움은 안될것 같네요 그럼 이만~
참 compare() 함수하고
IS_FULL() 함수는 아마 기존에 존재 하지 않은
프로그램 내의 정의되어 있는 사항 같네요
|