多项式 链表 乘法
来源:互联网 发布:android传递数据的方式 编辑:程序博客网 时间:2024/06/11 14:08
#ifndef POLY_H_INCLUDED
#define POLY_H_INCLUDED
//with header
struct polynode
{
int C;
int n;
struct polynode* next;
};
typedef struct polynode* list;
list init_list(list L)
{
L=(list)malloc(sizeof(struct polynode));
L->next = NULL;
return L;
}
void print_list(list L)
{
list p=L;
while (p->next!=NULL)
{
printf("%dX^%d",p->next->C,p->next->n);
if(p->next->next!=NULL) putchar('+');
p=p->next;
}
printf("\n");
}
list find(list head,int n) //在list中返回n的前导节点指针
{
while (head->next!=NULL)
{
if (head->next->n==n) break;
head = head->next;
}
return head;
}
void insert_list(list L,int C,int power) //插入
{
list r = find(L,power);
if (r->next!=NULL) r->next->C+=C;
else
{
list tmp = (list)malloc(sizeof(struct polynode));
tmp->C = C;
tmp->n = power;
list p=L;
while (p->next!=NULL)
{
if (p->next->n < power) break;
p=p->next;
}
tmp->next = p->next;
p->next = tmp;
}
}
void poly_mult(list A,list B,list result)
{
int c,n;
list p,q;
p=A;
int tmp_n,tmp_c;
while (p->next!=NULL)
{
n=p->next->n;
c=p->next->C;
q=B;
while (q->next!=NULL)
{
tmp_n=q->next->n + n;
tmp_c=q->next->C*c;
insert_list(result,tmp_c,tmp_n);
q=q->next;
}
p=p->next;
}
}
#endif // POLY_H_INCLUDED
- 多项式 链表 乘法
- 多项式乘法
- 多项式乘法
- 多项式乘法
- 多项式乘法
- 多项式乘法
- 大数乘法 和 多项式乘法
- ACM 多项式乘法
- 多项式加法、乘法
- 多项式加减乘法
- noj 1006 多项式乘法
- 【UOJ 34】多项式乘法
- FFT uoj34 多项式乘法
- [UOJ#34]多项式乘法
- FFT与多项式乘法
- UOJ 34 多项式乘法
- UOJ 34 多项式乘法
- matlab-基础 多项式乘法
- ADC12模块
- 逆序数&排序
- java线程同步原理、wait,notify的用法及与sleep的区别
- IOS cocos2d学习笔记-<八>游戏关卡(Objective-C文件读写)
- 找出数组中第二大的数
- 多项式 链表 乘法
- Apache Maven 入门篇(下)
- C#实现通过HttpWebRequest发送POST请求实现网站自动登陆
- ZOJ Goldbach 2013年长沙赛区网络赛
- (3)选择元素——(5)为项目列表加样式(Styling list-item levels)
- VC SDK 全屏截图代码
- 给Git或者APT设置代理
- MySQL Server Error Codes and Messages
- 盗QQ与反盗