데이터구조(다항식+링크드리스트)
본 자료는 4페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
해당 자료는 4페이지 까지만 미리보기를 제공합니다.
4페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

데이터구조(다항식+링크드리스트)에 대한 보고서 자료입니다.

목차

없음

본문내용

== first)
{
done = TRUE;
}
else
{
sum = first->coef + second->coef;
if(sum)
attach(sum, first->expon, &lastd);
first = first->link;
second = second->link;
}
break;
case 1:
attach(first->coef, first->expon,&lastd);
first = first->link;
}
} while(!done);
lastd->link = d;
return d;
}
void attach(int coefficient, int exponent, pointer *ptr)
{
pointer temp;
temp = (pointer)malloc(sizeof(node));
if(IS_FULL(temp)){
fprintf(stderr,"The memory is full\n");
exit(3);
}
temp->coef = coefficient;
temp->expon = exponent;
(*ptr)->link = temp;
*ptr = temp;
}
pointer psub(pointer first, pointer second)
{
pointer starta, d, lastd;
int subresult, done = FALSE;
starta = first;
first = first->link;
second = second->link;
d = (pointer)malloc(sizeof(node));
if(IS_FULL(d))
{
fprintf(stderr, "The memory is full\n");
exit(2);
}
d->expon = -1;
lastd = d;
do{
switch(COMPARE(first->expon, second->expon))
{
case -1:
second->coef = (-1)*second->coef;
attach(second->coef, second->expon, &lastd);
second = second->link;
break;
case 0:
if(starta == first)
done = TRUE;
else
{
subresult = first->coef - second->coef;
if(subresult)
attach(subresult, first->expon, &lastd);
first = first->link;
second = second->link;
}
break;
case 1:
attach(first->coef, first->expon, &lastd);
first = first->link;
}
} while(!done);
lastd->link = d;
return d;
}
pointer pmult(pointer first, pointer second)
{
pointer startfirst, startsecond, temp;
pointer resulta, resultc, lasta, lastc;
startfirst = first->link;
startsecond = second->link;
resulta = (pointer)malloc(sizeof(node));
if(IS_FULL(resulta))
{
fprintf(stderr, "The memory is full\n");
exit(2);
}
resulta->coef = -1;
resulta->expon = -1;
lasta = resulta;
lasta->link = resulta;
resultc = (pointer)malloc(sizeof(node));
if(IS_FULL(resultc))
{
fprintf(stderr, "The memory is full\n");
exit(2);
}
resultc->coef = -1;
resultc->expon = -1;
lastc = resultc;
lastc->link = resultc;
for( ;startsecond->expon != -1; startsecond = startsecond->link)
{
for( ;startfirst->expon != -1; startfirst = startfirst->link)
{
temp = (pointer)malloc(sizeof(node));
if(IS_FULL(temp))
{
fprintf(stderr, "The memory is full\n");
exit(2);
}
temp->coef = startfirst->coef * startsecond->coef;
temp->expon = startfirst->expon + startsecond->expon;
temp->link = lasta->link;
lasta->link = temp;
lasta = temp;
resultc = cpadd(resultc,resulta);
resulta->link = lasta->link;
free(lasta);
lasta = resulta;
}
startfirst = startfirst->link;
}
return resultc;
}
void eval(pointer polynomial, double f)
{
int expon;
double sum = 0;
double multsum = 1;
pointer Link;
Link = polynomial->link;
for( ;Link->expon != -1; Link = Link->link)
{
for(expon = Link->expon; expon >0; expon--)
multsum = multsum * f;
if(Link->expon != 0)
sum = sum + (Link->coef * multsum);
else
sum = sum + Link->coef;
multsum = 1;
}
printf("실수 %0.5f를 넣어서 계산된 결과 : %0.5f\n", f, sum);
}
void cerase(pointer *ptr)
{
pointer temp, last;
temp = (*ptr)->link;
while(temp!= *ptr)
{
last = temp->link;
free(temp);
temp = last;
}
free(*ptr);
}
  • 가격2,000
  • 페이지수14페이지
  • 등록일2011.10.31
  • 저작시기2011.6
  • 파일형식한글(hwp)
  • 자료번호#710625
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니