资源简介
数据结构与算法分析(C++语言版)张琨 第二章线性表一元多项式代码
代码片段和文件信息
#include“yiyuan.h“
#include
#include
using std::ostream;
using std::endl;
Poly::Poly()
{
/*PolyNode *Head;*/
Head = (PolyNode *)malloc(sizeof(PolyNode));
}
void Poly:: CreatPoly(PolyArray a int n)
{
PolyNode *s *r;
//Head = (PolyNode *)malloc(sizeof(PolyNode));
int i;
r = Head;
for (i = 0; i < n; i++)
{
s = new PolyNode;
s->coef = a[i].coef;
s->exp = a[i].exp;
s->next = nullptr;
r->next = s;
r = s;
}
}
void Poly::PolySort()
{
/*PolyNode *Head;
Head = (PolyNode *)malloc(sizeof(PolyNode));*/
PolyNode *p *q *r;
p = Head->next;
if (p != nullptr)
{
r = p->next;
p->next = nullptr;
p = r;
while (p != nullptr)
{
r = p->next;
q = Head;
while (q->next != nullptr&&q->next->exp < p->exp)
q = q->next;
p->next = q->next;
q->next = p;
p = r;
}
}
}
void Poly::PolyAdd(Poly LB)
{
/*PolyNode *Head;
Head = (PolyNode *)malloc(sizeof(PolyNode));*/
float sum;
PolyNode *pa *pb *qa *qb;
pa = Head;
qa = pa->next;
pb = LB.hhh();
qb = pb->next;
while (qa != nullptr&& qb != nullptr)
{
if (qa->exp < qb->exp)
{
pa = qa; qa = qa->next;
}
else if (qa->exp > qb->exp)
{
pb->next = qb->next;
qb->next = qa;
pa->next = qb;
pa = qb;
qb = pb->next;
}
else
{
sum = qa->coef + qb->coef;
if (sum == 0)
{
pa->next = qa->next;
delete qa;
qa = pa->next;
pb->next = qb->next;
delete qb;
qb = pb->next;
}
else
{
qa->coef = sum;
pa = qa; qa = qa->next;
pb->next = qb->next;
delete qb;
qb = pb->next;
}
}
}
if (qb != nullptr)
{
pa->next = qb;
}
}
void Poly::PolyDisplay()
{
PolyNode *x;
x = Head->next;
while (x!=nullptr)
{
std::cout << x->coef << “and“ << x->exp< x = x->next;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4204 2017-10-24 19:56 一元方程\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj
文件 1153 2017-10-24 19:56 一元方程\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj.filters
文件 764 2017-10-29 17:52 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.E564F607.tlog\cl.command.1.tlog
文件 9016 2017-10-29 17:52 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.E564F607.tlog\CL.read.1.tlog
文件 720 2017-10-29 17:52 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.E564F607.tlog\CL.write.1.tlog
文件 197 2017-10-29 17:52 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.E564F607.tlog\ConsoleApplication1.lastbuildstate
文件 3032 2017-10-29 17:52 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.E564F607.tlog\li
文件 6854 2017-10-29 17:52 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.E564F607.tlog\li
文件 704 2017-10-29 17:52 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.E564F607.tlog\li
文件 1554 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.F1D2BE9D.tlog\cl.command.1.tlog
文件 17512 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.F1D2BE9D.tlog\CL.read.1.tlog
文件 1820 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.F1D2BE9D.tlog\CL.write.1.tlog
文件 190 2017-10-24 22:31 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.F1D2BE9D.tlog\ConsoleApplication1.lastbuildstate
文件 3260 2017-10-24 22:31 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.F1D2BE9D.tlog\li
文件 7138 2017-10-24 22:31 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.F1D2BE9D.tlog\li
文件 900 2017-10-24 22:31 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleA.F1D2BE9D.tlog\li
文件 1385 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleApplication1.Build.CppClean.log
文件 2506 2017-10-24 22:31 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\ConsoleApplication1.log
文件 376799 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\dingyi.obj
文件 338944 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\vc120.idb
文件 290816 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\vc120.pdb
文件 137602 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\Debug\源.obj
文件 1919 2017-10-24 22:30 一元方程\ConsoleApplication1\ConsoleApplication1\dingyi.cpp
文件 415 2017-10-24 21:27 一元方程\ConsoleApplication1\ConsoleApplication1\yiyuan.h
文件 315 2017-10-24 21:20 一元方程\ConsoleApplication1\ConsoleApplication1\源.cpp
文件 7274496 2017-10-24 22:31 一元方程\ConsoleApplication1\ConsoleApplication1.sdf
文件 1003 2017-10-24 18:43 一元方程\ConsoleApplication1\ConsoleApplication1.sln
..A..H. 22016 2017-10-24 22:31 一元方程\ConsoleApplication1\ConsoleApplication1.v12.suo
文件 1054208 2017-10-24 22:30 一元方程\ConsoleApplication1\Debug\ConsoleApplication1.exe
文件 2558680 2017-10-24 22:31 一元方程\ConsoleApplication1\Debug\ConsoleApplication1.ilk
............此处省略11个文件信息
评论
共有 条评论