当前位置: 首页 > news >正文

网站宣传平台程序员接外包平台

网站宣传平台,程序员接外包平台,做家具厂招聘有哪些网站,wordpress插件汉化下载大家如果发现代码有错误#xff0c;麻烦评论告知一下!!! 下面的代码多项式相乘的算法实现并不是书上那种#xff0c;书上那种我实在是看不懂#xff0c;所以用了自己的方法写了相乘的算法#xff0c;就是模拟手算过程#xff0c;一个一个相乘。 代码如下: #include 麻烦评论告知一下!!! 下面的代码多项式相乘的算法实现并不是书上那种书上那种我实在是看不懂所以用了自己的方法写了相乘的算法就是模拟手算过程一个一个相乘。 代码如下: #include iostream using namespace std;typedef struct {double coef;int expn; }term,ElemType;typedef struct LNode {ElemType data;LNode *next; }*Link,*Position;typedef struct {Link head, tail;int len; }LinkList;typedef LinkList Polynomial;bool makeNode(Link p, ElemType e) {p new LNode;if (!p) return false;p-data e;p-next nullptr;return true; }void freeNode(Link p) {delete p;p nullptr; }bool initList(LinkList L) {L.head new LNode;if (!L.head) return false;L.tail L.head;L.head-next nullptr;L.len 0;return true; }bool insFirst(Link h, Link s) {s-next h-next;h-next s;return true; }bool delFirst(Link h, Link q) {q h-next;h-next h-next-next;q-next nullptr;return true; }bool append(LinkList L, Link s) {L.tail-next s;while (L.tail-next){L.tail L.tail-next;L.len;}return true; }bool remove(LinkList L, Link q) {LNode *s L.head;while (s-next ! L.tail){s s-next;}q L.tail;L.tail s;s-next nullptr;L.len--;return true; }bool insBefore(LinkList L, Link p, Link s) {LNode *q L.head;while (q-next ! p){q q-next;}s-next p;q-next s;L.len;return true; }bool insAfter(LinkList L, Link p, Link s) {s-next p-next;p-next s;p s;L.len;return true; }bool setCurElem(Link p, ElemType e) {p-data e;return true; }ElemType getCurElem(Link p) {return p-data; }int polynLength(Polynomial p) {int j 0;LNode *s p.head-next;while (s){j;s s-next;}p.len j;return p.len; }bool listEmpty(LinkList L) {polynLength(L);if (L.len 0) return true;else return false; }Position getHead(LinkList L) {return L.head; }Position getLast(LinkList L) {return L.tail; }Position priorPos(LinkList L, Link p) {LNode *s L.head;while (s-next ! p){s s-next;}if (s L.head){return nullptr;}return s; }Position nextPos(LinkList L, Link p) {return p-next; }bool locatePos(LinkList L, int i, Link p) {int j 1;LNode *s L.head-next;if (i 1 || i L.len) return false;while (s j i){s s-next;j;}if (!s || j i){return false;}p s;return true; }bool locateElem(LinkList L, ElemType e, Position q,int(*compare)(ElemType, ElemType)) {LNode *s L.head-next;while (s){if (compare(s-data, e) 0){q s;return true;}s s-next;}s L.head;while (s-next){if (compare(s-next-data, e) 0){q s;return false;}s s-next;}q s;return false; }int cmp(term a, term b) {if (a.expn b.expn) return -1;else if (a.expn b.expn) return 0;else if (a.expn b.expn) return 1; }void destroyPolyn(Polynomial L) {LNode *p L.head;while (p){LNode *q p;p p-next;delete q;}L.tail L.head nullptr; }void printPolyn(Polynomial p) {LNode *s p.head-next;int j 1;int len polynLength(p);while (s){if (s-data.expn 0){cout s-data.coef;}else{cout s-data.coef x^ s-data.expn;}if (j len)cout ;s s-next;j;}cout endl; }void createPolyn(Polynomial p, int n) {initList(p);LNode *s nullptr;LNode *h nullptr;LNode *q nullptr;h getHead(p);ElemType e;e.coef 0.0;e.expn -1;setCurElem(h, e);for (int i 0; i n; i){cin e.coef e.expn;if (e.coef 0.0)continue;if (!locateElem(p, e, q, cmp)){if (makeNode(s, e)){insFirst(q, s);}}}LNode *p1 p.head;while (p1-next){p1 p1-next;}p.tail p1; }void addPolyn(Polynomial pa, Polynomial pb) {LNode *ha getHead(pa);LNode *hb getHead(pb);LNode *qa nextPos(pa, ha);LNode *qb nextPos(pb, hb);while (qa qb){ElemType a getCurElem(qa);ElemType b getCurElem(qb);switch (cmp(a, b)){case -1:ha qa;qa nextPos(pa, qa);break;case 0:ElemType sum;sum.coef a.coef b.coef;sum.expn a.expn;if (sum.coef ! 0.0){setCurElem(qa, sum);ha qa;}else{delFirst(ha, qa);freeNode(qa);}delFirst(hb, qb);freeNode(qb);qb nextPos(pb, hb);qa nextPos(pa, ha);break;case 1:delFirst(hb, qb);insFirst(ha, qb);qb nextPos(pb, hb);ha nextPos(pa, ha);break;}}if (!listEmpty(pb)) append(pa, qb);freeNode(hb); }void subtractPolyn(Polynomial pa, Polynomial pb) {LNode *ha getHead(pa);LNode *hb getHead(pb);LNode *qa nextPos(pa, ha);LNode *qb nextPos(pb, hb);while (qa qb){ElemType a getCurElem(qa);ElemType b getCurElem(qb);switch (cmp(a, b)){case -1:ha qa;qa nextPos(pa, qa);break;case 0:ElemType sum;sum.coef a.coef - b.coef;sum.expn a.expn;if (sum.coef ! 0.0){setCurElem(qa, sum);ha qa;}else{delFirst(ha, qa);freeNode(qa);}delFirst(hb, qb);freeNode(qb);qb nextPos(pb, hb);qa nextPos(pa, ha);break;case 1:delFirst(hb, qb);insFirst(ha, qb);qb nextPos(pb, hb);ha nextPos(pa, ha);break;}}if (!listEmpty(pb)) append(pa, qb);freeNode(hb); }void multiplyPolyn(Polynomial pa, Polynomial pb) {Polynomial pc;initList(pc);LNode *ha getHead(pa);LNode *hb getHead(pb);LNode *qa nextPos(pa, ha);LNode *qb nextPos(pb, hb);LNode *s nullptr;LNode *q nullptr;ElemType e;while (qa){while (qb){e.coef qa-data.coef*qb-data.coef;if (qa-data.expn! 0 qb-data.expn!0)e.expn qa-data.expnqb-data.expn;if (qa-data.expn 0){e.expn qb-data.expn;}else if (qb-data.expn 0){e.expn qa-data.expn;}if (!locateElem(pc, e, q, cmp)){if (makeNode(s, e)){insFirst(q, s);}}else{q-data.coef e.coef;}qb nextPos(pb, qb);}qb nextPos(pb, hb);qa nextPos(pa, qa);}destroyPolyn(pa);destroyPolyn(pb);pa pc; }int main() {Polynomial L,L1;int n;cin n;createPolyn(L, n);printPolyn(L);cin n;createPolyn(L1, n);printPolyn(L1);cout polynLength(L) endl;cout polynLength(L1) endl;multiplyPolyn(L, L1);printPolyn(L);return 0; }
http://www.pierceye.com/news/283951/

相关文章:

  • 滨江区网站开发公司贵阳住房和城乡建设局网站
  • 如何建设小网站邢台市天气预报15天
  • 网站收录量低怎么做舟山公司网站制作
  • 部队网站模板计算机网站建设员
  • 对象储存做网站微博内网站怎么做的
  • 运城做网站要多少钱谷歌网站英文
  • 校园网站建设的意见与建议做儿童交互网站
  • 7黄页网站建设网站建设培训会讲话
  • 百度推广公司地址苏州优化方式
  • 做一个电商网站建设银行网站打不开用什么浏览器
  • 保定住房和城乡建设局网站沙洋网站定制
  • 北京电脑培训网站网站首页怎么做全屏swf
  • 网站建设 设计 优化 维护爱站网关键词挖掘工具
  • 做电影收费网站二级域名查询
  • 销售网站模板a5站长网网站交易
  • 网站需要怎么做的吗做营销网站那个好
  • 苏州网站建设软件收费广东网站设计哪家专业
  • 中国产品网免费网站网站自定义功能实现
  • 做微信小程序和做网站短视频素材下载网站
  • 自治区住房和城乡建设厅网站自己怎么健网站视频教程
  • 昆明建站网址dw怎么做秋季运动会网站
  • 为什么要建设个人网站在建工程
  • o2o网站设计方案做一个网站只做前端怎么做
  • 长沙网站建设公司联系方式网站注册手机号安全吗
  • 广州市网站建设服务机构建设部网站查资质
  • 医院网站建设思路wordpress mx主题
  • 天津如何做百度的网站虚拟机做局域网网站服务器
  • 网站建设维护需要懂哪些知识网站建设优质公司
  • 怎么做网络彩票网站校园网站建设经费申请报告
  • 廊坊公司做网站一般网站图标是用什么做的