單鏈表(
單鏈表應用
有人曾經建議最好把鏈表和鏈表位置這兩個分開
ListNode<Term> *pa
ListIterator<Term> Aiter(ah
ListIterator<Term> Biter(ah
pa = pc = Aiter
………………………
pa
p = pb; pb = Biter
pa
如果從基本的節點操作入手
一元多項式類定義與實現
#ifndef Polynomial_H
#define Polynomial_H
#include
class Term
{
public:
int coef;
int exp;
Term() : coef(
Term(int c
Term(int c) : coef(c)
};
class Polynomial : List<Term>
{
public:
void Input()
{
cout << endl <<
cout << endl <<
int coef
for(int i =
{
cout <<
cin >> coef;
if (coef)
{
cout <<
cin >> exp;
Term term(coef
Insert(term);
}
else break;
}
}
void Print()
{
cout << endl;
First();
if (!IsEmpty())
{
Term *p = Next();
cout << p
if (p
{
cout <<
if (p
}
while (Next() != NULL)
{
p = Get();
if (p
cout << p
if (p
{
cout <<
if (p
}
}
}
cout << endl;
}
friend void PolyAdd (Polynomial &polyA
{
Node<Term> *pA
polyA
pA = polyA
while (pA != NULL && pB !=NULL)
{
if (pA
{
pA
polyB
if (!pA
else polyA
}
else
{
if (pA
{
polyB
polyA
}
else if (pA
}
pA = polyA
}
if (pA == NULL)
{
polyA
polyB
}
}
};
#endif
【說明】對於多項式
在下面將會有些重載運算符的例子
From:http://tw.wingwit.com/Article/program/sjjg/201311/22943.html