| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

问题点数：0  回复次数：2

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

typedef struct PolyNode *PtrPolyNode;
struct PolyNode //结构体类型声明忘记写分号
{
int coef;
int expon;
struct PolyNode *next;
};

PtrPolyNode  CreatePolyList(int N)
{
PtrPolyNode previous,current;

int i;

for( i=0 ; i<N ; i++)
{
current = ( PtrPolyNode )malloc( sizeof( struct PolyNode) ) ;
current->next = NULL ;

scanf("%d" , &(current->coef) ) ;   //忘记给系数和指数赋值
scanf("%d" , &(current->expon) ) ;

else
previous->next = current ;

previous = current ;
}
}

/*PtrPolyNode Addition( PtrPolyNode Poly1 , PtrPolyNode Poly2 )
{
PtrPolyNode current,previous;

while( Poly1!=NULL )
{
if( Poly1->expon==Poly2->expon && Poly2!=NULL ) //指数相同时系数相加，保存
{
current = ( PtrPolyNode ) malloc( sizeof(struct PolyNode) );

current->next = NULL ;
current->coef = Poly1->coef + Poly2->coef;
current->expon = Poly1->expon;

else
previous->next=current;

previous=current;

Poly1=Poly1->next;
Poly2=Poly2->next;/*由于指数按递减排序，故不需要将Poly1第k项与Poly2所有项比较，
Poly2高阶项匹配到以后直接从它的下一项开始扫描*/
/*        }

if( Poly1->expon != Poly2->expon && Poly2!=NULL )
{
Poly2=Poly2->next;    //与Poly2下一项比较
}

if( Poly2==NULL )        //Poly2中没有项能与Poly1第K项匹配，将其保存后进入k+1项的匹配
{
current = ( PtrPolyNode ) malloc( sizeof(struct PolyNode) );

current->next = NULL ;
current->coef = Poly1->coef;
current->expon = Poly1->expon;

else
previous->next=current;

previous=current;

Poly1=Poly1->next;
}
}

}
*/

{

{

}
printf("\n");
}

int main()
{
int N1,N2;        //非0项个数
PtrPolyNode Poly1,Poly2,Poly3;

scanf("%d",&N1);
Poly1 = CreatePolyList( N1 ) ;

scanf("%d",&N2);
Poly2 = CreatePolyList( N2 ) ;

OutPut( Poly1 );
OutPut( Poly2 );

//Poly3 = Addition( Poly1 , Poly2 );
//    OutPut( Poly3 );
}```

得分:0

[此贴子已经被作者于2015-10-26 12:15编辑过]

得分:0

[此贴子已经被作者于2015-10-26 12:15编辑过]

• 3
• 1/1页
• 1