数据结构问题没有语法错误就是搞啦好久哪位大神帮帮忙

liuzhiqi 发布于 2012/10/24 22:48

/* PRESET CODE BEGIN - NEVER TOUCH CODE BELOW */

#include <stdio.h>
#include <stdlib.h>

typedef struct node
{   int    coef, exp;
struct node  *next;
} NODE;

void multiplication( NODE *, NODE * , NODE * );
void input( NODE * );
void output( NODE * );

void input( NODE * head )
{   int flag, sign, sum, x;
char c;

while ( (c=getchar()) !='\n' )
{
if ( c == '<' )
{    sum = 0;
sign = 1;
flag = 1;
}
else if ( c =='-' )
sign = -1;
else if( c >='0'&& c <='9' )
{    sum = sum*10 + c - '0';
}
else if ( c == ',' )
{    if ( flag == 1 )
{    x = sign * sum;
sum = 0;
flag = 2;
sign = 1;
}
}
else if ( c == '>' )
{    p->next = ( NODE * ) malloc( sizeof(NODE) );
p->next->coef = x;
p->next->exp  = sign * sum;
p = p->next;
p->next = NULL;
flag = 0;
}
}
}

void output( NODE * head )
{
while ( head->next != NULL )
}
printf("\n");
}
void multiplication( NODE *h1, NODE *h2 , NODE *h3 )
{
NODE *p,*q,*r, *r1,*s;
int Max;

p = h1->next;
s = NULL;
r1 = NULL;

while(p ->next != NULL){
q = h2 -> next;
Max = p->exp;
while(q ->next != NULL)
{
r->coef = p->coef * q->coef;
r->exp = p->exp + q->exp;
r = r->next;
if(r->exp > Max )    {
Max = r->exp;
}
}
if(p->next == NULL&&q->next == NULL)
{ free(p);
free(q);
}
if(r->coef == 0)
{
free(r);
break;
}
for(int i = Max; i >= 0 ; i++){
s->next = (NODE*)malloc(sizeof(NODE));
s->coef = r->coef;
s->exp = r->exp;
r = r->next;
}
while( s)
{

NODE *p2 , *q2, *r1 = h3;
p2 = r1 -> next;
q2 = s;
r1->next = NULL;
while (p2 != NULL)
{
q2 = p2->next;
p2->next = r1->next;
r1-> next = p2;
p2 = q2;
}
free(s);
}
}
}

int main()

head1 = ( NODE * ) malloc( sizeof(NODE) );

head2 = ( NODE * ) malloc( sizeof(NODE) );

head3 = ( NODE * ) malloc( sizeof(NODE) );

return 0;
}

/* PRESET CODE END - NEVER TOUCH CODE ABOVE */

0

l

0

l