?? 多項式的加減運算.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0042)http://vip.6to23.com/dcyu/TurboC/DS/1.html -->
<HTML><HEAD><TITLE>Turbo C</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>BODY {
SCROLLBAR-FACE-COLOR: #ffffff
}
INPUT {
FONT-SIZE: 12px; FONT-FAMILY: "宋體"
}
INPUT {
FONT-SIZE: 12px; FONT-FAMILY: "宋體"
}
.border {
BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; COLOR: #000000; BORDER-BOTTOM: 1px dotted; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #efefef
}
.border {
BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; COLOR: #000000; BORDER-BOTTOM: 1px dotted; BORDER-COLLAPSE: collapse; BACKGROUND-COLOR: #efefef
}
.input {
FONT-SIZE: 9pt; FONT-FAMILY: 宋體,Verdana, Arial, Helvetica, sans-serif
}
.links {
FONT-SIZE: 9pt; COLOR: #000000; FONT-FAMILY: 宋體,Verdana, Arial, Helvetica, sans-serif
}
</STYLE>
<META content="sumipntg 011, default" name="Microsoft Theme">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY text=#000066 vLink=#666699 aLink=#990099 link=#3333cc bgColor=#ffffff
background=多項式的加減運算.files/sumtextb.htm>
<P> </P>
<DIV align=center>
<P><BR><A href="http://www.6to23.com/vip/asp/"><BR></A></P>
<TABLE height=24 cellSpacing=0 cellPadding=0 width=689 align=center border=0>
<TBODY>
<TR>
<TD width=94>
<P align=center><FONT color=#0000ff size=2> </FONT><A
href="http://vip.6to23.com/dcyu/TurboC/summarize.html"><FONT color=#0000ff
size=2>概述</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/basic.html"><FONT color=#0000ff
size=2>初級篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/advance.html"><FONT color=#0000ff
size=2>中級篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/senior.html"><FONT color=#0000ff
size=2>高級篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/sutra.html"><FONT color=#0000ff
size=2>經典篇</FONT></A></P></TD>
<TD width=94>
<P align=center><A
href="http://vip.6to23.com/dcyu/TurboC/algorithm.html"><FONT color=#0000ff
size=2>算法篇</FONT></A></P></TD>
<TD width=94>
<P align=center><FONT size=2> </FONT><A
href="http://vip.6to23.com/dcyu/TurboC/DS.html"><FONT color=#0000ff
size=2><SPAN
style="BACKGROUND-COLOR: #00ff00">數據結構</SPAN></FONT></A></P></TD>
<TD width=100>
<P align=center><A href="http://vip.6to23.com/dcyu/index.html"><FONT
color=#0000ff size=2>回到首頁</FONT></A> </P></TD></TR></TBODY></TABLE>
<TABLE height=542 cellSpacing=0 cellPadding=0 width=619 border=0>
<TBODY>
<TR>
<TD vAlign=top width=138 bgColor=#ffffff height=493>
<TABLE height=482 cellSpacing=0 cellPadding=0 width=686
background=多項式的加減運算.files/vccode.htm border=0>
<TBODY>
<TR>
<TD align=left width="100%" height=21>1.多項式的加減運算
<P><FONT color=#0000ff>問題</FONT>:使用鏈表操作實現多項式的加減運算。</P>
<P><FONT
color=#0000ff>算法</FONT>:鏈表的基本操作,包括插入、刪除、合并等操作,下面是實現加減法的核心程序。</P>
<P>typedef struct Polyn<BR>{<BR> float coef; /* 系數
*/<BR> int expn; /* 冪 */<BR> struct Polyn *next; /*
下一節(jié)點的指針 */<BR>} Polyn;</P>
<P>Polyn *add(Polyn *heada,Polyn *headb)<BR>{<BR> Polyn
*headc,*p,*q,*s,*r;<BR> float
x;<BR> p=heada;q=headb;<BR> headc=(Polyn
*)malloc(sizeof(Polyn));<BR> r=headc;<BR> while
(p!=NULL&&q!=NULL)<BR> {<BR>
if(p->expn==q->expn) /* 指數相等 */<BR>
{<BR>
x=p->coef+q->coef;<BR>
if(x!=0)<BR> {<BR>
s=(Polyn *)malloc(sizeof(Polyn));<BR>
s->coef=x;<BR>
s->expn=p->expn;<BR>
r->next=s;<BR>
r=s;<BR> }<BR>
p=p->next;<BR> q=q->next;<BR>
}<BR> else /* 比較的時候已經通過sort函數按多項式的冪排序 */<BR>
if(p->expn<q->expn) /* 總是記錄冪大者的信息 */<BR>
{<BR> s=(Polyn
*)malloc(sizeof(Polyn));<BR>
s->coef=q->coef;<BR>
s->expn=q->expn; /* 記錄q指針的信息
*/<BR>
r->next=s;<BR>
r=s;<BR>
q=q->next;<BR> }<BR> else<BR>
{<BR> s=(Polyn
*)malloc(sizeof(Polyn));<BR>
s->coef=p->coef;<BR> s->expn=p->expn;
/* 記錄p指針的信息 */<BR>
r->next=s;<BR> r=s;<BR>
p=p->next;<BR> }<BR> }<BR> while(p!=NULL) /*
將p或q的剩余未運算的多項式各項信息記錄在s指針中 */<BR> {<BR> s=(Polyn
*)malloc(sizeof(Polyn));<BR>
s->coef=p->coef;<BR>
s->expn=p->expn;<BR> r->next=s;<BR>
r=s;<BR>
p=p->next;<BR> }<BR> while(q!=NULL)<BR> {<BR>
s=(Polyn *)malloc(sizeof(Polyn));<BR>
s->coef=q->coef;<BR>
s->expn=q->expn;<BR> r->next=s;<BR>
r=s;<BR>
q=q->next;<BR> }<BR> r->next=NULL;<BR> s=headc;<BR> headc=headc->next;<BR> free(s);<BR> return(headc);<BR>}<BR><BR>Polyn
*sub(Polyn *heada,Polyn *headb) /* 減法就是加法的逆運算 */<BR>{<BR> Polyn
*r,*hc;<BR> r=headb;<BR> while(r!=NULL) /*
headb多項式系數全變成原來的相反數 */<BR> {<BR>
r->coef=-r->coef;<BR>
r=r->next;<BR> }<BR> hc=add(heada,headb); /* 相加
*/<BR> return hc;<BR>}<BR></P>
<P>程序:<A href="http://vip.6to23.com/dcyu/TurboC/DS/Polyn.zip"><FONT
color=#0000ff>Polyn.zip</FONT></A><FONT
color=#0000ff>
</FONT><FONT
color=#0000ff>
</FONT><A href="http://vip.6to23.com/dcyu/TurboC/DS/2.html"><FONT
color=#0000ff>下一頁</FONT></A></P>
<P> </P></TD></TR>
<TR>
<TD align=left width="100%" height=21>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<HR align=center width=740 color=#8fb373 noShade SIZE=1>
<TABLE cellSpacing=0 cellPadding=0 width="90%" border=0>
<TBODY>
<TR bgColor=#949231>
<TD height=3></TD></TR></TBODY></TABLE>
<TABLE height=37 width=490>
<TBODY>
<TR>
<TD vAlign=top align=left width=486 height=8>
<P align=center><FONT size=2><FONT face=Arial>Copyright
2001-2002</FONT>,<FONT face=Arial>dcyu, All rights reserved</FONT>,
上次更新:2002-10-13</FONT> <FONT color=#000000><BR></FONT><FONT
color=#000080 size=2>E-mail : <A
href="mailto:dcyu@163.net">dcyu@163.net</A> QQ :
28009316 </FONT></P></TD></TR>
<TR>
<TD class=mainfont vAlign=top align=left width=486 height=17>
<P align=center><FONT size=2>建議使用IE 5.0以上版本進行瀏覽
最佳顯示分辨率800*600</FONT></P></TD></TR></TBODY></TABLE> </DIV></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -