锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲av综合avav中文,亚洲精品无码MV在线观看,亚洲欧洲第一a在线观看http://www.tkk7.com/matthew2006/archive/2006/11/20/82264.htmlmatthewmatthewMon, 20 Nov 2006 06:59:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/11/20/82264.htmlhttp://www.tkk7.com/matthew2006/comments/82264.htmlhttp://www.tkk7.com/matthew2006/archive/2006/11/20/82264.html#Feedback2http://www.tkk7.com/matthew2006/comments/commentRss/82264.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/82264.html 鑻ヨ鍦?i>n涓煄甯備箣闂村緩璁鵑氳緗戠粶錛屽彧闇瑕佹灦璁?i>n-1鏉$嚎璺嵆鍙傚浣曚互鏈浣庣殑緇忔祹浠d環寤鴻榪欎釜閫氳緗戠粶錛屾槸涓涓綉鐨勬渶灝忕敓鎴愭爲闂銆傛湰鍗曞厓鐨勫疄楠屽唴瀹逛富瑕佹槸鍒╃敤鍏嬮瞾鏂崱灝旂畻娉曟眰鍑虹綉鐨勬渶灝忕敓鎴愭爲錛屽茍涓斾互鏂囨湰褰㈠紡杈撳嚭鏍戜腑鐨勫悇鏉¤竟浠ュ強浠栦滑鐨勬潈鍊箋?br />
#include<iostream>
#include<stdlib.h>//浜х敓闅忔満鏁扮粍鐢?br />#include<time.h> //鍚屼笂
聽#include<list>

聽// 1) 甯︽潈杈圭殑綾籑yArc:

class MyArc
{
public:
聽聽聽 int m_beginVex;
聽聽聽 int m_endVex;
聽聽聽 int m_weight;
聽聽聽 MyArc(int beginVex,int endVex,int weight);
聽聽聽 MyArc(){}
聽聽聽 bool operator < (const MyArc& arc)
聽聽聽 {
聽聽聽聽聽聽聽 return m_weight<arc.m_weight;
聽聽聽 }
聽聽聽 bool operator == (const MyArc& arc)
聽聽聽 {
聽聽聽聽聽聽聽 return m_weight==arc.m_weight;
聽聽聽 }
聽聽聽 bool operator > (const MyArc& arc)
聽聽聽 {
聽聽聽聽聽聽聽 return m_weight>arc.m_weight;
聽聽聽 }
}聽 ;

MyArc::MyArc(int beginVex,int endVex,int weight):m_beginVex(beginVex),m_endVex(endVex),m_weight(weight)
{}
//2) 琛ㄧず鍥劇殑閭繪帴鐭╅樀綾籊raph:
class Graph
{
public:
聽聽聽 int m_vexnum;
聽聽聽 int m_arcnum;
聽聽聽 int *m_pmatrix;
public:
聽聽聽 ~Graph();
聽聽聽 Graph(int vexnum);
聽聽聽 Graph(int vexnum,int *pmatrix);
聽聽聽 void insert(MyArc arc);//鎸夋潈鍊煎ぇ灝忔帓搴忔彃鍏?br />聽聽聽 bool bound(int x);聽聽 //鍒ゆ柇欏剁偣x鏄惁宸蹭笌鍏跺畠欏剁偣榪為?br />};
//鏋勯犲嚱鏁?br />Graph::Graph(int vexnum)
{
聽聽聽 m_pmatrix=new int[vexnum*vexnum];
聽聽聽 m_vexnum=vexnum;m_arcnum=0;
聽聽聽 for(int i=0;i<vexnum*vexnum;++i)
聽聽聽 m_pmatrix[i]=0;

}

//鏋勯犲嚱鏁?br />Graph::Graph(int vexnum,int *pmatrix)
{
聽聽聽 m_vexnum=vexnum;
聽聽聽 // m_arcnum=arcnum;
聽聽聽 m_pmatrix=new int[m_vexnum*m_vexnum];
聽聽聽 for(int i=0;i<m_vexnum*m_vexnum;++i)
聽聽聽聽聽聽聽 m_pmatrix[i]=pmatrix[i];
}

//嫻嬭瘯 欏剁偣x鏄惁宸蹭笌鍏朵粬鐐硅繛閫?br />bool Graph::bound(int x)
{
聽聽聽 for(int i=0;i<m_vexnum;++i) if(m_pmatrix[x+i*m_vexnum]!=0) return true;
聽聽聽 return false;
}

//鍦ㄩ偦鎺ヨ〃涓繛閫?arc琛ㄧず鐨勮竟錛屽茍涓旇緗潈
void Graph::insert(MyArc arc)
{
聽聽聽 m_pmatrix[arc.m_beginVex*m_vexnum+arc.m_endVex]=arc.m_weight;
聽聽聽 m_pmatrix[arc.m_endVex*m_vexnum+arc.m_beginVex]=arc.m_weight;
聽聽聽 ++m_arcnum;
}
//鏋愭瀯
Graph::~Graph()
{
聽聽聽 delete[] m_pmatrix;
}
//3) 鎸夋潈瀛樺偍杈圭殑鏈夊簭闃熷垪綾籑yQueues:

//杈規寜鏉冨兼彃鍏ラ槦鍒椾腑鍚堥備綅緗?
class MyQueues
{
public:
聽聽聽 list<MyArc> m_list;
聽聽聽 MyQueues(){}
聽聽聽 void insert(const MyArc& arc);//杈規寜鏉冨兼彃鍏ラ槦鍒椾腑鍚堥備綅緗?
聽聽聽 void InsertGraph(const Graph &graph);//灝嗗浘鐨勮繛閫氬垎閲忔彃鍏ラ槦鍒?br />聽聽聽 MyArc pop();
};
//杈瑰嚭闃?br />MyArc MyQueues::pop()
{
聽聽聽 MyArc arc=m_list.front();
聽聽聽 m_list.pop_front();
聽聽聽 return arc;
}
//杈規寜鏉冨兼彃鍏ラ槦鍒椾腑鍚堥備綅緗?
void MyQueues::insert(const MyArc& arc)
{
聽聽聽 list<MyArc>::iterator pos;
聽聽聽 pos=m_list.begin();
聽聽聽 while(pos!=m_list.end())
聽聽聽 {
聽聽聽聽聽聽聽 if(*pos>arc) break;
聽聽聽聽聽聽聽 else ++pos;
聽聽聽 }
聽聽聽 m_list.insert(pos,arc);
}
//灝嗗浘鐨勮繛閫氬垎閲忔彃鍏ラ槦鍒?br />void MyQueues::InsertGraph(const Graph &graph)
{
聽聽聽 for(int i=0;i<graph.m_vexnum;++i)
聽聽聽 {
聽聽聽聽聽聽聽 for(int j=i+1;j<graph.m_vexnum;++j)
聽聽聽聽聽聽聽聽聽聽聽聽聽 if(graph.m_pmatrix[i*graph.m_vexnum+j]) insert(MyArc(i,j,graph.m_pmatrix[i*graph.m_vexnum+j]));
聽聽聽 }
}

聽//5)鍒ゆ柇鏄惁鏈夊洖璺殑IsCycle鍑芥暟錛?br />bool IsCycle(Graph& graph, MyArc& arc)
{
聽聽聽 list<int> my_list;
聽聽聽 my_list.push_back(arc.m_beginVex);
聽聽聽 int *ps=new int[graph.m_vexnum];
聽聽聽 for(int i=0;i<graph.m_vexnum;++i)
聽聽聽聽聽聽聽 ps[i]=0;
聽聽聽 while(!my_list.empty())
聽聽聽 {
聽聽聽聽聽聽聽 int x=my_list.front();
聽聽聽聽聽聽聽 ps[x]=1;
聽聽聽聽聽聽聽 my_list.pop_front();
聽聽聽聽聽聽聽 for(int i=0;i<graph.m_vexnum;++i)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽 if(graph.m_pmatrix[i+x*graph.m_vexnum]!=0)
聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 if(i==arc.m_endVex) return true;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 if(ps[i]!=1) my_list.push_back(i);
聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 }
聽聽聽 }
聽聽聽 delete[] ps;
聽聽聽 return false;
}
//4) kruskal綆楁硶:
void kruskal(const Graph& graph,Graph& smtree)
{
聽聽聽 MyQueues arcqueues;//淇濆瓨浠庡皬鍒板ぇ鎺掑垪鐨勮竟
聽聽聽 arcqueues.InsertGraph(graph);
聽聽聽 MyArc myarc;//Arc琛ㄧず杈圭殑綾誨瀷
聽聽聽 int arcnum=0; //杈圭殑涓暟
聽聽聽 while(arcnum<graph.m_vexnum-1)
聽聽聽 {
聽聽聽聽聽聽聽 myarc=arcqueues.pop();
聽聽聽聽聽聽聽 if(!IsCycle(smtree,myarc))
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽 smtree.insert(myarc);
聽聽聽聽聽聽聽聽聽聽聽聽聽 ++arcnum;
聽聽聽聽聽聽聽 }
聽聽聽 }
}


void SetMatrix(int vexnum,int *pmatrix)
{
聽聽聽 srand((unsigned)time(NULL));
聽聽聽 for(int i=0;i<vexnum;++i)//浜х敓闅忔満鏉冨肩煩闃?br />聽聽聽 {
聽聽聽聽聽聽聽 for(int j=i;j<vexnum;++j)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽 if(j==i)
聽聽聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 pmatrix[i*vexnum+j]=0;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 continue;
聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽 int rnum=rand();rnum%=99;rnum++;//浜х敓1~99鐨勯殢鏈烘暣鏁頒綔涓鴻竟鐨勬潈鍊?br />聽聽聽聽聽聽聽聽聽聽聽聽聽 pmatrix[i*vexnum+j]=rnum;
聽聽聽聽聽聽聽聽聽聽聽聽聽 pmatrix[j*vexnum+i]=rnum;
聽聽聽聽聽聽聽 }
聽聽聽 }
聽聽聽 cout<<"***闅忔満浜х敓鐨勫悇杈規潈鍊肩煩闃?[欏剁偣鏁頒負 "<<vexnum<<"] ****\n";
聽 for(int i=0;i<vexnum;++i)//杈撳嚭闅忔満鏉冨肩煩闃?br />聽聽聽 {
聽聽聽聽聽聽聽 for(int j=0;j<vexnum;++j)
聽聽聽聽聽聽聽 {
聽聽聽聽聽聽聽聽聽聽聽聽聽 cout<<pmatrix[i*vexnum+j]<<"\t";
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽 cout<<endl;
聽聽聽 }

}

void SmallestTreeOutput(const Graph& smtree)
{
聽聽聽 cout<<"鏈灝忕敓鎴愭爲:"<<endl;
聽聽聽 for(int i=0;i<smtree.m_vexnum;++i)//杈撳嚭鏈灝忔爲
聽聽聽聽聽聽聽 for(int j=i+1;j<smtree.m_vexnum;++j)
聽聽聽聽聽聽聽聽聽聽聽聽聽 if(smtree.m_pmatrix[i*smtree.m_vexnum+j])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 cout<<'('<<i<<','<<j<<','<<smtree.m_pmatrix[i*smtree.m_vexnum+j]<<')'<<endl;
}

void main()
{
聽聽聽 char i;
聽聽聽 cout<<"璇瘋緭鍏ラ《鐐規暟鐩?";
聽聽聽 cin>>i;
聽 int vex=i-'0';
聽聽聽 int *matrix=new int[vex*vex];
聽聽聽 cout<<endl;
聽聽聽 SetMatrix(vex,matrix);
聽聽聽 Graph graph(vex,matrix),smtree(vex);
聽聽聽 kruskal(graph,smtree);
聽聽聽 SmallestTreeOutput(smtree);
聽聽聽 delete []matrix;
}


緇撴灉杈撳嚭錛?br />璇瘋緭鍏ラ《鐐規暟鐩?6

***闅忔満浜х敓鐨勫悇杈規潈鍊肩煩闃?[欏剁偣鏁頒負 6] ****
0聽聽聽聽聽聽 64聽聽聽聽聽 7聽聽聽聽聽聽 15聽聽聽聽聽 22聽聽聽聽聽 43
64聽聽聽聽聽 0聽聽聽聽聽聽 72聽聽聽聽聽 86聽聽聽聽聽 53聽聽聽聽聽 40
7聽聽聽聽聽聽 72聽聽聽聽聽 0聽聽聽聽聽聽 53聽聽聽聽聽 37聽聽聽聽聽 22
15聽聽聽聽聽 86聽聽聽聽聽 53聽聽聽聽聽 0聽聽聽聽聽聽 87聽聽聽聽聽 82
22聽聽聽聽聽 53聽聽聽聽聽 37聽聽聽聽聽 87聽聽聽聽聽 0聽聽聽聽聽聽 9
43聽聽聽聽聽 40聽聽聽聽聽 22聽聽聽聽聽 82聽聽聽聽聽 9聽聽聽聽聽聽 0
鏈灝忕敓鎴愭爲:
(0,2,7)
(0,3,15)
(0,4,22)
(1,5,40)
(4,5,9)



matthew 2006-11-20 14:59 鍙戣〃璇勮
]]>
C璇█-鍒ゆ柇瀛楃涓叉槸鍚﹀洖鏂?/title><link>http://www.tkk7.com/matthew2006/archive/2006/11/05/79211.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Sun, 05 Nov 2006 08:58:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/11/05/79211.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/79211.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/11/05/79211.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/79211.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/79211.html</trackback:ping><description><![CDATA[ <p> <font face="Arial">聽聽 "鍥炴枃"鏄寚欏鴻鍜屽弽璇誨唴瀹歸兘鐩稿悓鐨勫瓧絎︿覆錛屽錛?ABCCBA"錛庤繖閲屽紩鍏ヤ袱涓寚閽堝彉閲忥紝寮濮嬫椂錛?br /><br />鍒嗗埆鎸囧悜瀛楃涓茬殑棣栨湯瀛楃錛屽綋涓や釜鎸囬拡鎵鎸囧瓧絎︾浉絳夋椂錛屼袱鎸囬拡鍒嗗埆鍚戝墠鍚戝悗縐諱竴涓瓧絎︿綅緗紝<br /><br />騫剁戶緇瘮杈冿紝鐩村埌涓ゆ寚閽堢浉閬囷紟鍒欒鏄庤瀛楃涓叉槸鍥炴枃錛庤嫢姣旇緝榪囩▼涓紝鍙戠幇涓ゅ瓧絎︿笉鐩哥瓑錛屽垯<br /><br />鍙互鍒ゆ柇璇ュ瓧絎︿覆涓嶆槸鍥炴枃錛?br /><br /><strong>浠g爜濡備笅錛?br /><br /></strong><em>/*鍒ゆ柇瀛楃涓叉槸鍚︽槸鍥炴枃*/</em></font> </p> <p> <font face="Arial"> <em>#include<stdio.h><br />#define MAX 50<br />int cycle(char *s)<br />{<br />聽 char *h,*t;<br />聽 for(h=s,t=s+strlen(s)-1;t>h;h++,t--)<br />聽 {<br />聽聽聽 if(*h!=*t)<br />聽聽聽 {<br />聽聽聽聽聽聽聽 printf("%c",h);<br />聽聽聽聽聽聽聽 break;<br />聽聽聽 }<br />聽 }<br />聽 return t<=h;<br />}</em> </font> </p> <p> <font face="Arial"> <em>main()<br />{<br />聽 char s[MAX];<br />聽 while(1)<br />聽 {<br />聽聽聽 puts("Please input the string you want to judge(input ^ to quit):");<br />聽聽聽 scanf("%s",s);<br />聽聽聽 if(s[0]=='^')<br />聽聽聽聽聽 break;<br />聽聽聽 if(cycle(s))<br />聽聽聽 printf("%s is a cycle string.\n",s);<br />聽聽聽 else<br />聽聽聽 printf("%s is not a cycle string.\n",s);<br />聽 }<br />聽 puts("\nThank you for you using ,bye bye!\n");<br />}<br /><br /></em> <strong>杈撳嚭緇撴灉錛?br /><br /></strong>Please input the string you want to judge(input ^ to quit):<br />abcabc<br />聽abcabc is not a cycle string.<br />Please input the string you want to judge(input ^ to quit):<br />abccba<br />abccba is a cycle string.<br />Please input the string you want to judge(input ^ to quit):</font> </p> <p> <font face="Arial"> <strong> </strong> </font>聽</p> <p> <font face="Arial"> <strong> <br /> </strong> </font>聽</p> <img src ="http://www.tkk7.com/matthew2006/aggbug/79211.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-11-05 16:58 <a href="http://www.tkk7.com/matthew2006/archive/2006/11/05/79211.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>C璇█鐨勬販鍚堣緭鍏ユ暟瀛楀拰瀛楃闂http://www.tkk7.com/matthew2006/archive/2006/11/03/78914.htmlmatthewmatthewFri, 03 Nov 2006 06:12:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/11/03/78914.htmlhttp://www.tkk7.com/matthew2006/comments/78914.htmlhttp://www.tkk7.com/matthew2006/archive/2006/11/03/78914.html#Feedback0http://www.tkk7.com/matthew2006/comments/commentRss/78914.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/78914.html銆鍋囧浣犵殑紼嬪簭鍚屾椂闇瑕佷嬌鐢╣etchar()榪涜瀛楃杈撳叆鍜屼嬌鐢?scanf()榪涜鏁板瓧杈撳叆錛庤繖涓や釜鍑芥暟鐨勬瘡涓涓兘鑳藉緢濂界殑瀹屾垚宸ヤ綔錛?br />浣嗘槸瀹冧滑涓嶈兘寰堝ソ鍦版販鍚堝湪涓璧鳳紟榪欐槸鍥犱負getchar()璇誨彇姣忎釜瀛楃錛屽寘鎷┖鏍鹼紝鍒惰〃絎﹀拰鎹㈣絎︼紱鑰宻canf()鍦ㄨ鍙栨暟瀛楁椂鍊欏垯
浼氳煩榪囩┖鏍鹼紝鍒惰〃絎﹀拰鎹㈣絎︼紟涓嬮潰鏄釜渚嬪瓙錛?br />char1.cpp
/*C璇█涓涓狪/O闂紼嬪簭*/
#include<stdio.h>
void display(char cr,int lines,int width);
int main(void)
{
聽 int ch;
聽 int rows,cols;
聽 printf("Enter a character and tow integers:\n");
聽 while((ch=getchar())!='\n')
聽 {
聽聽聽聽 scanf("%d %d",&rows,&cols);
聽聽聽聽 display(ch,rows,cols);

聽聽聽聽 printf("Enter another character and tow integers;\n");
聽聽聽聽 printf("Enter a newline to quit.\n");
聽 }
聽 printf("Bye.\n");
聽 return 0;
}
void display(char cr,int lines,int width)
{
聽 int row ,col;
聽 for(row =1;row<=lines;row++)
聽 {
聽聽聽 for(col=1;col<=width;col++)
聽聽聽 {
聽聽聽聽聽 putchar(cr);
聽聽聽聽聽聽 }
聽聽聽聽聽 putchar('\n');

聽 }
}
緇撴灉杈撳嚭錛?br /> Enter a character and tow integers:
d 3 2
dd
dd
dd
Enter another character and tow integers;
Enter a newline to quit.
Bye.
Press any key to continue...

銆鍙互鐪嬭绱ц窡鍦?鍚庨潰鐨勯偅涓崲琛岀錛宻canf()鍑芥暟灝嗚鎹㈣絎︾暀鍦ㄤ簡杈撳叆闃熷垪涓紟鑰実etchar()騫朵笉璺寵繃鎹㈣絎︼紝鎵浠ュ湪寰幆鐨?br />涓嬩竴鍛ㄦ湡錛屽湪浣犳湁鏈轟細杈撳叆鍏朵粬鍐呭涔嬪墠錛岃繖涓崲琛岀鐢眊etchar()璇誨嚭錛岀劧鍚庡皢鍏惰祴鍊肩粰ch錛岃宑h涓烘崲琛岀姝f槸緇堟寰幆鐨勬潯浠訛紟

銆瑕佽В鍐寵繖涓棶棰橈紝蹇呴』璺寵繃涓涓緭鍏ュ懆鏈熶腑閿叆鐨勬渶鍚庝竴涓暟瀛椾笌涓嬩竴琛屽紑濮嬪閿叆鐨勫瓧絎︿箣闂寸殑鎵鏈夋崲琛岀鎴栫┖鏍鹼紟
鏀硅繘濡備笅錛?strong>char2.cpp

/*C璇█涓涓狪/O闂紼嬪簭淇敼鐗堟湰*/
#include<stdio.h>
void display(char cr,int lines,int width);
int main(void)
{
聽 int ch;
聽 int rows,cols;
聽 printf("Enter a character and tow integers:\n");
聽 while((ch=getchar())!='\n')
聽 {
聽聽聽 if( scanf("%d %d",&rows,&cols)!=2)
聽聽聽 break;
聽聽聽聽 display(ch,rows,cols);
聽聽聽聽 while(getchar()!='\n')聽聽聽聽聽 /*鍓旈櫎鎺塻canf()杈撳叆鍚庣殑鎵鏈夊瓧絎︼紟*/
聽聽聽聽 {

聽聽聽聽聽聽聽 printf("1");聽聽聽聽聽聽聽聽聽 /*鍚庨潰鏈夊灝戝瓧絎﹀氨杈撳嚭澶氬皯涓?*/
聽聽聽聽聽聽聽 continue;

聽聽聽聽 }
聽聽聽聽 printf("Enter another character and tow integers;\n");
聽聽聽聽 printf("Enter a newline to quit.\n");
聽 }
聽 printf("Bye.\n");
聽 return 0;
}
void display(char cr,int lines,int width)
{
聽 int row ,col;
聽 for(row =1;row<=lines;row++)
聽 {
聽聽聽 for(col=1;col<=width;col++)
聽聽聽 {
聽聽聽聽聽 putchar(cr);
聽聽聽聽聽聽 }
聽聽聽聽聽 putchar('\n');

聽 }
}

杈撳嚭緇撴灉錛?br />Enter a character and tow integers:
d 3 4
dddd
dddd
dddd
Enter another character and tow integers;
Enter a newline to quit.
d 3 4
dddd
dddd
dddd
11Enter another character and tow integers;
Enter a newline to quit.



matthew 2006-11-03 14:12 鍙戣〃璇勮
]]>
閫掑綊鍑芥暟璋冪敤錛嶇畝鍗曟湁鏁?/title><link>http://www.tkk7.com/matthew2006/archive/2006/11/02/78760.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Thu, 02 Nov 2006 11:13:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/11/02/78760.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/78760.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/11/02/78760.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/78760.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/78760.html</trackback:ping><description><![CDATA[ <p> <span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 瀹嬩綋; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">涓嬮潰鏄釜鍏充簬閫掑綊璋冪敤綆鍗曚絾鏄緢鑳借鏄庨棶棰樼殑渚嬪瓙錛?br /><br /><em>/*閫掑綊渚嬪瓙*/<br />#include<stdio.h><br />void up_and_down(int);<br />int main(void)<br />{<br />聽聽 up_and_down(1);<br />聽聽 return 0;<br />}<br />void up_and_down(int n)<br />{<br />聽 printf("Level %d:n location %p\n",n,&n); /* 1 */<br />聽 if(n<4)<br />聽 up_and_down(n+1);<br />聽 printf("Level %d:n location %p\n",n,&n); /* 2 */<br />}<br /><br /></em><strong>杈撳嚭緇撴灉<br /></strong>Level 1:n location 0240FF48<br />Level 2:n location 0240FF28<br />Level 3:n location 0240FF08<br />Level 4:n location 0240FEE8<br />Level 4:n location 0240FEE8<br />Level 3:n location 0240FF08<br />Level 2:n location 0240FF28<br />Level 1:n location 0240FF48<br /><br /></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆棣栧厛錛?/span> <span lang="EN-US"> <font face="Times New Roman">main()</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">浣跨敤鍙傛暟</span> <span lang="EN-US"> <font face="Times New Roman">1</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璋冪敤浜嗗嚱鏁?/span> <span lang="EN-US"> <font face="Times New Roman">up_and_down()</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛屼簬鏄?/span> <span lang="EN-US"> <font face="Times New Roman">up_and_down()</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">涓艦寮忓弬鏁?/span> <span lang="EN-US"> <font face="Times New Roman">n</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鐨勫兼槸</span> <span lang="EN-US"> <font face="Times New Roman">1,</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鏁呮墦鍗拌鍙?/span> <span lang="EN-US"> <font face="Times New Roman">#1</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">杈撳嚭浜?/span> <span lang="EN-US"> <font face="Times New Roman">Level1</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆?br />鐒跺悗錛岀敱浜?/span> <span lang="EN-US"> <font face="Times New Roman">n</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鐨勬暟鍊煎皬浜?/span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛屾墍浠?/span> <span lang="EN-US"> <font face="Times New Roman">up_and_down()</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛堢</span> <span lang="EN-US"> <font face="Times New Roman">1</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰э級浣跨敤鍙傛暟</span> <span lang="EN-US"> <font face="Times New Roman">n+1</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍗蟲暟鍊?/span> <span lang="EN-US"> <font face="Times New Roman">2</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璋冪敤浜?/span> <span lang="EN-US"> <font face="Times New Roman">up_and_down()(</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">絎?/span> <span lang="EN-US"> <font face="Times New Roman">2</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰?/span> <span lang="EN-US"> <font face="Times New Roman">).</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">浣垮緱</span> <span lang="EN-US"> <font face="Times New Roman">n</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍦ㄧ</span> <span lang="EN-US"> <font face="Times New Roman">2<br /></font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄤ腑琚祴鍊?/span> <span lang="EN-US"> <font face="Times New Roman">2,</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鎵撳嵃璇彞</span> <span lang="EN-US"> <font face="Times New Roman">#1</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">杈撳嚭鐨勬槸</span> <span lang="EN-US"> <font face="Times New Roman">Level2</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆備笌涔嬬被浼鹼紝涓嬮潰鐨勪袱嬈¤皟鐢ㄥ垎鍒墦鍗板嚭</span> <span lang="EN-US"> <font face="Times New Roman">Level3</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍜?/span> <span lang="EN-US"> <font face="Times New Roman">Level4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆?br /></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> <br />銆褰撳紑濮嬫墽琛岀</span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄦ椂錛?/span> <span lang="EN-US"> <font face="Times New Roman">n</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鐨勫兼槸</span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛屽洜姝?/span> <span lang="EN-US"> <font face="Times New Roman">if</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璇彞鐨勬潯浠朵笉婊¤凍銆傝繖鏃跺欎笉鍐嶇戶緇皟鐢?/span> <span lang="EN-US"> <font face="Times New Roman">up_and_down()</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍑芥暟銆傜</span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄦ帴<br />鐫鎵ц鎵撳嵃璇彞</span> <span lang="EN-US"> <font face="Times New Roman">#2</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛屽嵆杈撳嚭</span> <span lang="EN-US"> <font face="Times New Roman">Level4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛屽洜涓?/span> <span lang="EN-US"> <font face="Times New Roman">n</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鐨勫兼槸</span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆傜幇鍦ㄥ嚱鏁伴渶瑕佹墽琛?/span> <span lang="EN-US"> <font face="Times New Roman">return</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璇彞錛屾鏃剁</span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄧ粨鏉燂紝鎶婃帶鍒舵潈榪斿洖緇欒<br />鍑芥暟鐨勮皟鐢ㄥ嚱鏁幫紝涔熷氨鏄</span> <span lang="EN-US"> <font face="Times New Roman">3</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄥ嚱鏁般傜</span> <span lang="EN-US"> <font face="Times New Roman">3</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄥ嚱鏁頒腑鍓嶄竴涓墽琛岃繃鐨勮鍙ユ槸鍦?/span> <span lang="EN-US"> <font face="Times New Roman">if</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璇彞涓繘琛岀</span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄣ傚洜姝わ紝瀹冪戶<br />緇墽琛屽叾鍚庣戶浠g爜錛屽嵆鎵ц鎵撳嵃璇彞</span> <span lang="EN-US"> <font face="Times New Roman">#2</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛岃繖灝嗕細杈撳嚭</span> <span lang="EN-US"> <font face="Times New Roman">Level3</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛庡綋絎?/span> <span lang="EN-US"> <font face="Times New Roman">3</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄧ粨鏉熷悗錛岀</span> <span lang="EN-US"> <font face="Times New Roman">2</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綰ц皟鐢ㄥ嚱鏁板紑濮嬬戶緇墽琛岋紝鍗寵緭鍑?br /></span> <span lang="EN-US"> <font face="Times New Roman">Level2</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛庝緷嬈$被鎺紟</span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">銆娉ㄦ剰錛屾瘡涓綰х殑閫掑綊閮戒嬌鐢ㄥ畠鑷繁鐨勭鏈夌殑鍙橀噺</span> <span lang="EN-US"> <font face="Times New Roman">n</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛庡彲浠ユ煡鐪嬪湴鍧鐨勫兼潵璇佹槑錛?br /><br /></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> <strong>閫掑綊鐨勫熀鏈師鐞嗭細<br /><br /></strong> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛戙姣忎竴嬈″嚱鏁拌皟鐢ㄩ兘浼氭湁涓嬈¤繑鍥烇紟褰撶▼搴忔祦鎵ц鍒版煇涓綰ч掑綊鐨勭粨灝懼鏃訛紝瀹冧細杞Щ鍒板墠涓綰ч掑綊緇х畫鎵ц錛?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛掋閫掑綊鍑芥暟涓紝浣嶄簬閫掑綊璋冪敤鍓嶇殑璇彞鍜屽悇綰ц璋冨嚱鏁板叿鏈夌浉鍚岀殑欏哄簭錛庡鎵撳嵃璇彞</span> <span lang="EN-US"> <font face="Times New Roman">#1</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">浣嶄簬閫掑綊璋冪敤璇彞鍓嶏紝瀹冩寜鐓ч?br />銆銆褰掕皟鐢ㄧ殑欏哄簭琚墽琛屼簡</span> <span lang="EN-US"> <font face="Times New Roman">4</font> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">嬈★紟</span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛撱姣忎竴綰х殑鍑芥暟璋冪敤閮芥湁鑷繁鐨勭鏈夊彉閲忥紟</span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛斻閫掑綊鍑芥暟涓紝浣嶄簬閫掑綊璋冪敤璇彞鍚庣殑璇彞鐨勬墽琛岄『搴忓拰鍚勪釜琚皟鐢ㄥ嚱鏁扮殑欏哄簭鐩稿弽錛?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛曘铏界劧姣忎竴綰ч掑綊鏈夎嚜宸辯殑鍙橀噺錛屼絾鏄嚱鏁頒唬鐮佸茍涓嶄細寰楀埌澶嶅埗錛?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛栥閫掑綊鍑芥暟涓繀欏誨寘鍚彲浠ョ粓姝㈤掑綊璋冪敤鐨勮鍙ワ紟</span> </p> <p>鍐嶇湅涓涓叿浣撶殑閫掑綊鍑芥暟璋冪敤鐨勪緥瀛愶細<strong>浠ヤ簩榪涘埗褰㈠紡杈撳嚭鏁存暟<br /><br />/*杈撳叆涓涓暣鏁幫紝杈撳嚭浜岃繘鍒跺艦寮?/<br /></strong><em>#include<stdio.h><br />void to_binary(unsigned long n);</em></p> <p> <em>int main(void)<br />{<br />聽 unsigned long number;<br />聽 printf("Enter an integer(q to quit):\n");<br />聽 while(scanf("%ul",&number)==1)<br />聽 {<br />聽聽聽 printf("Binary equivalent :");<br />聽聽聽 to_binary(number);<br />聽聽聽 putchar('\n');<br />聽聽聽 printf("Enter an integer(q to quit):\n");<br />聽 }<br />聽 printf("Done.\n");<br />聽 return 0;<br />聽 <br />}<br />void to_binary(unsigned long n)聽聽聽 /*閫掑綊鍑芥暟*/<br />{<br />聽 int r;<br />聽 r=n%2;聽聽聽 /*鍦ㄩ掑綊璋冪敤涔嬪墠璁$畻n%2鐨勬暟鍊鹼紝鐒跺悗鍦ㄩ掑綊璋冪敤璇彞涔嬪悗榪涜杈撳嚭錛庤繖鏍?br />聽 銆銆銆銆銆銆璁$畻鍑虹殑絎竴涓暟鍊煎弽鑰屾槸鍦ㄦ渶鍚庝竴涓緭鍑?/<br />聽 if(n>=2)<br />聽 to_binary(n/2);<br />聽 putchar('0'+r);/*濡傛灉r鏄?錛岃〃杈懼紡'0'+r灝辨槸瀛楃'0'錛涘鏋渞鏄?錛屽垯琛ㄨ揪寮忕殑鍊間負<br />聽 銆銆銆銆銆銆銆銆銆'1'錛庢敞鎰忓墠鎻愭槸瀛楃'1'鐨勬暟鍊肩紪鐮佹瘮瀛楃'0'鐨勬暟鍊肩紪鐮佸ぇ1錛?br />聽 銆銆銆銆銆銆銆銆銆ASCII鍜孍BCDIC榪欎袱縐嶇紪鐮侀兘婊¤凍榪欎釜鏉′歡錛?/<br />聽 return;<br />}</em> </p> <span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 瀹嬩綋; mso-bidi-font-size: 12.0pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"> <p> <br /> </p> </span> <strong>聽杈撳嚭緇撴灉涓猴細<br /><br /></strong>Enter an integer(q to quit):<br />9<br />Binary equivalent :1001<br />Enter an integer(q to quit):<br />255<br />Binary equivalent :11111111<br />Enter an integer(q to quit):<p><strong></strong>聽</p><img src ="http://www.tkk7.com/matthew2006/aggbug/78760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-11-02 19:13 <a href="http://www.tkk7.com/matthew2006/archive/2006/11/02/78760.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏁版嵁緇撴瀯錛嶄覆鐨勬ā寮忓尮閰?/title><link>http://www.tkk7.com/matthew2006/archive/2006/10/31/78344.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Tue, 31 Oct 2006 10:50:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/10/31/78344.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/78344.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/10/31/78344.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/78344.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/78344.html</trackback:ping><description><![CDATA[ <p>1銆佸緩绔嬬洰鏍囦覆s鍜屾ā寮忎覆t<br />2銆侀噰鐢ㄧ畝鍗曠畻娉曟眰t鍦╯涓殑浣嶇疆<br />3銆佺敱妯″紡涓瞭姹傚嚭next鍊煎拰nextval鍊?br />4銆侀噰鐢↘MP綆楁硶鍜孠MP鏀硅繘綆楁硶姹倀鍦╯涓殑浣嶇疆<br /><br /><em><strong>浠g爜濡備笅錛?br /></strong>#include<stdio.h><br />#include<string.h><br />#define MaxSize 100</em></p> <p> <em>typedef struct<br />{<br />聽char ch[MaxSize];<br />聽int len;<br />}SqString;</em> </p> <p> <em>int Index(SqString s,SqString t)/* 綆鍗曞尮閰嶆柟娉?/<br />{<br />聽 int i=0,j=0,k;<br />聽 while(i<s.len&&j<t.len)<br />聽 {<br />聽聽聽 if(s.ch[i]==t.ch[j])/*緇х畫鍖歸厤涓嬩竴涓瓧絎?/ <br />聽{<br />聽聽 i++;<br />聽聽 j++;<br />聽}<br />聽else/*瀛愪覆銆佷富涓茬殑鎸囬拡鍥炴函閲嶆柊寮濮嬩笅涓嬈″尮閰?/ <br />聽{<br />聽 i=i-j+1;<br />聽 j=0;<br />聽}<br />聽 }<br />聽 if(j>=t.len)/*鍖歸厤鎴愬姛錛岃繑鍥炲尮閰嶇殑絎竴涓瓧絎︿笅鏍?/ <br />聽聽 k=i-t.len;<br />聽 else/*鍖歸厤涓嶆垚鍔?/ <br />聽聽 k=-1;<br />聽 return k;<br />}</em> </p> <p> <em>void GetNext(SqString t,int next[])/*鐢辨ā寮忎覆t姹傚嚭next鍊?/<br />{<br />聽int j,k;<br />聽j=0;k=-1;next[0]=-1;<br />聽while(j<t.len-1)<br />聽{<br />聽聽 if(k==-1||t.ch[j]==t.ch[k])<br />聽聽 {<br />聽聽聽聽 j++;k++;<br />聽聽聽聽 next[j]=k;<br />聽聽 }<br />聽聽 else k=next[k];<br />聽} <br />}</em> </p> <p> <em>void GetNextval(SqString t,int nextval[])/*鐢辨ā寮忎覆t姹傚嚭nextval鍊?/<br />{<br />聽聽 int j=0,k=-1;<br />聽聽 nextval[0]=-1;<br />聽聽 while(j<t.len)<br />聽聽 {<br />聽聽聽 if(k==-1||t.ch[j]==t.ch[k])<br />聽聽聽 {<br />聽聽聽聽聽 j++;k++;<br />聽聽 if(t.ch[j]!=t.ch[k])<br />聽聽 <br />聽聽聽 nextval[j]=k;<br />聽聽 else<br />聽聽聽聽聽聽 nextval[j]=nextval[k];</em> </p> <p> <em>聽聽 }<br />聽聽 else k=nextval[k];<br />聽聽聽 <br />聽聽 }<br />}<br />int KMPIndex(SqString s,SqString t)/*KMP綆楁硶*/<br />{<br />聽聽 int next[MaxSize];<br />聽聽 int i=0,j=0;<br />聽聽 int v;<br />聽聽 GetNext(t,next);<br />聽聽 while(i<s.len && j<t.len)<br />聽聽 {<br />聽聽聽聽 if(j==-1||s.ch[i]==t.ch[j])<br />聽聽聽聽 {<br />聽聽聽聽 聽i++;<br />聽聽聽聽 聽j++;<br />聽聽 }<br />聽聽 else j=next[j];<br />聽聽 }<br />聽聽 if(j>=t.len)<br />聽聽 v=i-t.len;<br />聽聽 else<br />聽聽 v=-1;<br />聽聽 return v;<br />}</em> </p> <p> <em>int KMPIndex1(SqString s,SqString t)/*鏀硅繘鐨凨MP綆楁硶*/<br />{<br />聽int nextval[MaxSize],next[MaxSize],i=0,j=0,v;<br />聽GetNextval(t,next);<br />聽GetNextval(t,nextval);<br />聽while(i<s.len&&j<t.len)<br />聽{<br />聽 if(i==-1||s.ch[i]==t.ch[j])<br />聽 {<br />聽聽聽 i++;<br />聽j++;<br />聽 }<br />聽 else j=nextval[j];<br />聽}<br />聽if(j>=t.len)<br />聽 v=i-t.len;/*榪斿洖鍖歸厤妯″紡涓茬殑棣栧瓧絎︿笅鏍?/<br />聽else <br />聽 v=-1;<br />聽return v;<br />}</em> </p> <p> <em>void StrAssign(SqString &str,char cstr[])/*鐢變覆甯擱噺cstr鍒涘緩涓瞫tr */<br />{<br />聽聽 int i;<br />聽聽 for(i=0;cstr[i]!='\0';i++)<br />聽聽聽 str.ch[i]=cstr[i];<br />聽聽 str.len=i;<br />}</em> </p> <p> <em>void DispStr(SqString s)/*杈撳嚭涓瞫鐨勬墍鏈夊厓绱?/<br />{<br />聽 int i;<br />聽 if(s.len>0)<br />聽 {<br />聽聽聽 for(i=0;i<s.len;i++)<br />聽聽printf("%c",s.ch[i]);<br />聽printf("\n");<br />聽 }<br />}<br />void main()<br />{<br />聽 int j;<br />聽 int next[MaxSize],nextval[MaxSize];<br />聽 SqString s,t;<br />聽 StrAssign(s,"abcabcdabcdeabcdefabcdefg");<br />聽 StrAssign(t,"abcdeabcdefab");<br />聽 printf("涓瞫:");DispStr(s);<br />聽 printf("涓瞭:");DispStr(t);</em> </p> <p> <em>聽 printf("綆鍗曞尮閰峆綆楁硶:\n");<br />聽 printf("t鍦╯涓殑浣嶇疆:%d\n",Index(s,t));</em> </p> <p> <em>聽 GetNext(t,next);<br />聽 GetNextval(t,nextval);<br />聽 printf(" j聽聽聽聽 ");<br />聽 for(j=0;j<t.len;j++)<br />聽 {<br />聽聽 printf("%4d",j);<br />聽 }<br />聽 printf("\n");<br />聽 printf("t[j]聽聽 ");<br />聽 for(j=0;j<t.len;j++)<br />聽 printf("%4c",t.ch[j]);<br />聽 printf("\n");<br />聽 printf("next聽聽 ");<br />聽 for(j=0;j<t.len;j++)<br />聽 printf("%4d",next[j]);<br />聽聽 printf("\n");<br />聽聽 <br />聽聽 printf("nextval");<br />聽聽 for(j=0;j<t.len;j++)<br />聽聽 printf("%4d",nextval[j]);<br />聽聽 printf("\n");</em> </p> <p> <em>聽聽 printf("KMP綆楁硶:\n");<br />聽聽 printf("t鍦╯涓殑浣嶇疆:%d\n",KMPIndex(s,t));</em> </p> <p> <em>聽聽 printf("鏀硅繘鐨凨MP綆楁硶:\n");<br />聽聽 printf("t鍦╯涓殑浣嶇疆:%d\n",KMPIndex1(s,t));</em> </p> <p> <em>}</em> <br /> <br /> <strong>緇撴灉濡備笅錛?/strong> <br />涓瞫:abcabcdabcdeabcdefabcdefg<br />涓瞭:abcdeabcdefab<br />綆鍗曞尮閰峆綆楁硶:<br />t鍦╯涓殑浣嶇疆:7<br />聽j聽聽聽聽聽聽聽 0聽聽 1聽聽 2聽聽 3聽聽 4聽聽 5聽聽 6聽聽 7聽聽 8聽聽 9聽 10聽 11聽 12<br />t[j]聽聽聽聽聽 a聽聽 b聽聽 c聽聽 d聽聽 e聽聽 a聽聽 b聽聽 c聽聽 d聽聽 e聽聽 f聽聽 a聽聽 b<br />next聽聽聽聽 -1聽聽 0聽聽 0聽聽 0聽聽 0聽聽 0聽聽 1聽聽 2聽聽 3聽聽 4聽聽 5聽聽 0聽聽 1<br />nextval聽 -1聽聽 0聽聽 0聽聽 0聽聽 0聽 -1聽聽 0聽聽 0聽聽 0聽聽 0聽聽 5聽 -1聽聽 0<br />KMP綆楁硶:<br />t鍦╯涓殑浣嶇疆:7<br />鏀硅繘鐨凨MP綆楁硶:<br />t鍦╯涓殑浣嶇疆:7</p> <img src ="http://www.tkk7.com/matthew2006/aggbug/78344.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-10-31 18:50 <a href="http://www.tkk7.com/matthew2006/archive/2006/10/31/78344.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏁版嵁緇撴瀯涔嬫爲鍙婂叾搴旂敤鈥旀渶浼樻帓璇?/title><link>http://www.tkk7.com/matthew2006/archive/2006/10/29/77902.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Sun, 29 Oct 2006 06:57:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/10/29/77902.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/77902.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/10/29/77902.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/77902.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/77902.html</trackback:ping><description><![CDATA[ <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <b style="mso-bidi-font-weight: normal"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 榛戜綋"> <font face="Arial"> <font size="4">瀛︾敓閫夎緋葷粺<span lang="EN-US"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?><o:p></o:p></span></font> </font> </span> </b> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"> <span style="FONT-FAMILY: 妤蜂綋_GB2312">澶у閲屽疄琛屽鍒嗗埗銆傛瘡闂ㄨ閮芥湁涓瀹氱殑瀛?/span> <span style="FONT-FAMILY: 瀹嬩綋">鍒?/span> <span style="FONT-FAMILY: 妤蜂綋_GB2312">銆傛瘡涓鐢熷潎闇瑕佷慨婊¤瀹氭暟閲忕殑璇劇▼鎵嶈兘姣曚笟銆傚叾涓湁浜涜紼嬪彲浠ョ洿鎺ヤ慨璇伙紝鏈変簺璇劇▼闇瑕佷竴瀹氱殑鍩虹鐭ヨ瘑錛屽繀欏誨湪閫変簡鍏朵粬涓浜涜紼嬬殑鍩虹涓婃墠鑳戒慨璇匯備緥濡傦紝銆婃暟鎹粨鏋勩嬪繀欏誨湪閫変慨浜嗐婇珮綰ц璦紼嬪簭璁捐銆嬩箣鍚庢墠鑳介変慨銆傛垜浠О銆婇珮綰ц璦紼嬪簭璁捐銆嬫槸銆婃暟鎹粨鏋勩嬬殑鈥滃厛淇鈥濄傚湪鎴戜滑鐨勫ぇ瀛﹂噷錛屽亣瀹?font color="#000000" size="2">姣忛棬璇劇殑鐩存帴鍏堜慨璇?span style="COLOR: red"><font color="#000000">鑷沖</font></span>鍙湁涓闂紝涓ら棬璇懼彲鑳藉瓨鍦ㄧ浉鍚岀殑鍏堜慨璇?/font>銆備緥濡傦細<span lang="EN-US"><o:p></o:p></span></span> </p> <table class="MsoNormalTable" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 36.9pt; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellspacing="0" cellpadding="0" border="1"> <tbody> <tr style="HEIGHT: 23.1pt"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 110.45pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 23.1pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt" valign="top" width="147"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璇懼彿</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 120.95pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 23.1pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="161"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍏堜慨璇懼彿</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 136.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 23.1pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="182"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">瀛﹀垎</span> </p> </td> </tr> <tr style="HEIGHT: 23.75pt"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 110.45pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 23.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="147"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">1</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 120.95pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 23.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="161"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">0</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 136.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 23.75pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="182"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">1</span> </p> </td> </tr> <tr style="HEIGHT: 22.4pt"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 110.45pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 22.4pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="147"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">2</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 120.95pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 22.4pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="161"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">1</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 136.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 22.4pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="182"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">1</span> </p> </td> </tr> <tr style="HEIGHT: 25.15pt"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 110.45pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 25.15pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="147"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">3</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 120.95pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 25.15pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="161"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">2</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 136.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 25.15pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="182"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">3</span> </p> </td> </tr> <tr style="HEIGHT: 20.25pt"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 110.45pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 20.25pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="147"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">4</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 120.95pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 20.25pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="161"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">0</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 136.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 20.25pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="182"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">3</span> </p> </td> </tr> <tr style="HEIGHT: 16.1pt; mso-yfti-lastrow: yes"> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 110.45pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 16.1pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="147"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">5</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 120.95pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 16.1pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="161"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">2</span> </p> </td> <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #ece9d8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #ece9d8; WIDTH: 136.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 16.1pt; BACKGROUND-COLOR: transparent; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt" valign="top" width="182"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center" align="center"> <span lang="EN-US">4</span> </p> </td> </tr> </tbody> </table> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"> <span lang="EN-US"> <o:p>聽</o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 妤蜂綋_GB2312">涓婁緥涓紝<span lang="EN-US">1</span>鏄?span lang="EN-US">2</span>鐨勫厛淇錛屽嵆濡傛灉瑕侀変慨<span lang="EN-US">2</span>錛屽垯<span lang="EN-US">1</span>蹇呭畾琚夈?span lang="EN-US"><o:p></o:p></span></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span style="FONT-FAMILY: 妤蜂綋_GB2312">瀛︾敓涓嶅彲鑳藉瀹屽ぇ瀛﹂噷寮璁劇殑鎵鏈夎紼嬶紝鍥犳姣忎釜瀛︾敓蹇呴』鍦ㄥ叆瀛︽椂閫夊畾鑷繁瑕佸鐨勮紼嬨傛瘡涓鐢熷彲閫夎紼嬬殑鎬繪暟鐩槸緇欏畾鐨勩傜幇鍦ㄨ浣犱滑灝忕粍緙栧啓涓涓滃鐢熼夎緋葷粺鈥濓紝<font size="2"><font color="#000000">浠繪剰緇欏畾涓縐嶈紼嬩綋緋伙紙鎬昏紼嬫暟錛岃紼嬩箣闂寸殑淇鍏堝悗鍒剁害鍏崇郴錛屽鐢熸瘯涓氳姹備慨鐨勮紼嬫暟鐩級錛岃緋葷粺鑳藉府鍔╁鐢熸壘鍑?span style="COLOR: red"><font color="#000000">涓縐?/font></span>閫夎鏂規錛屼嬌寰椾粬鑳藉緱鍒扮殑瀛﹀垎<span style="COLOR: red"><font color="#000000">鏈澶?/font></span>錛屽茍涓斿繀欏繪弧瓚?span style="COLOR: red"><font color="#000000">鍏堜慨璇劇▼浼樺厛</font></span>鐨勫師鍒?br /></font><span lang="EN-US"><o:p></o:p></span></font></span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; mso-char-indent-count: 2.0"> <font size="3"> <strong> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鍏蜂綋瀹炵幇濡備笅錛?/span>聽</strong> </font> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <o:p> <font face="Times New Roman" size="3">聽</font> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore"> <font face="Times New Roman"> <font size="3">1.</font> <span style="FONT: 7pt 'Times New Roman'">聽聽聽聽聽聽聽聽 </span> </font> </span> </span> <font size="3"> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">灝?b style="mso-bidi-font-weight: normal"><span style="COLOR: red"><font color="#000000">璇劇▼浣撶郴瀛樻斁涓鴻紼嬩綋緋繪枃浠?/font></span></b></span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">CourseHierarchy.txt</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">錛?/span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore"> <font face="Times New Roman"> <font size="3">2.</font> <span style="FONT: 7pt 'Times New Roman'">聽聽聽聽聽聽聽聽 </span> </font> </span> </span> <font size="3"> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">灝?b style="mso-bidi-font-weight: normal"><span style="COLOR: red"><font color="#000000">璇劇▼浣撶郴鏂囦歡</font></span></b></span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">CourseHierarchy.txt</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">杞崲宸﹀瀛愬彸鍏勫紵<b style="mso-bidi-font-weight: normal"><span style="COLOR: red"><font color="#000000">浜屽弶鏍戣〃紺?/font></span></b>錛?/span> </font> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore"> <font face="Times New Roman"> <font size="3">3.</font> <span style="FONT: 7pt 'Times New Roman'">聽聽聽聽聽聽聽聽<font color="#000000"></font></span> </font> </span> </span> <b style="mso-bidi-font-weight: normal"> <span style="COLOR: red; FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'"> <font color="#000000" size="3">鍦ㄦ鍩虹涓婂浜屽弶鏍戣繘琛屽厛搴忋佷腑搴忋佸悗搴忛亶鍘嗐?/font> </span> </b> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 42pt; TEXT-INDENT: -21pt; mso-list: l0 level1 lfo1; tab-stops: list 42.0pt"> <span lang="EN-US" style="mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore"> <font face="Times New Roman"> <font size="3">4.</font>聽<span style="FONT: 7pt 'Times New Roman'">聽聽聽聽聽銆<font face="Arial"><font size="2">緇欏嚭<font face="瀹嬩綋">鏈澶氬鍒嗛夎鏂規銆?/font></font></font><span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 12.0pt; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><br /><br /></span></span></font> </span> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">灝嗚紼嬩綋緋繪枃浠惰漿鎹負浜屽弶鏍?/span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鎬濇兂錛氫粠</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">CourseHierarchy.txt</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">澶撮儴寮濮嬫壂鎻忥紝絎竴涓厛淇涓?/span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">0</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">錛堝嵆娌℃湁鍏堜慨璇撅級鐨勮紼嬩負鏁存5浜屽弶鏍戠殑鏍硅妭鐐?/span> <i style="mso-bidi-font-style: normal"> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">i</font> </span> </i> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">銆備粠</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">CourseHierarchy.txt</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">澶撮儴寮濮嬫壂鎻忥紝鎵鏈?/span> <i style="mso-bidi-font-style: normal"> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">i</font> </span> </i> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐨勫悗緇紼嬩綔涓?/span> <i style="mso-bidi-font-style: normal"> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">i</font> </span> </i> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐨勫乏瀛愭爲錛涜紼嬩綋緋諱腑錛屽叾浠栧厛淇涓?/span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">0</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐨勮妭鐐癸紝鍙婂叾鍚庣畫璇劇▼鏋勬垚</span> <i style="mso-bidi-font-style: normal"> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">i</font> </span> </i> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐨勫彸瀛愭爲銆傜涓涓厛淇涓?/span> <i style="mso-bidi-font-style: normal"> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">i</font> </span> </i> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐨勮妭鐐逛綔涓?/span> <i style="mso-bidi-font-style: normal"> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">i</font> </span> </i> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐨勫乏瀛愭爲鐨勬牴鑺傜偣</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <span style="POSITION: relative; TOP: 6pt; mso-text-raise: -6.0pt"> <?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /?> <v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <font face="Times New Roman"> <v:stroke joinstyle="miter"> </v:stroke> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"> </v:f> <v:f eqn="sum @0 1 0"> </v:f> <v:f eqn="sum 0 0 @1"> </v:f> <v:f eqn="prod @2 1 2"> </v:f> <v:f eqn="prod @3 21600 pixelWidth"> </v:f> <v:f eqn="prod @3 21600 pixelHeight"> </v:f> <v:f eqn="sum @0 0 1"> </v:f> <v:f eqn="prod @6 1 2"> </v:f> <v:f eqn="prod @7 21600 pixelWidth"> </v:f> <v:f eqn="sum @8 21600 0"> </v:f> <v:f eqn="prod @7 21600 pixelHeight"> </v:f> <v:f eqn="sum @10 21600 0"> </v:f> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"> </v:path> <o:lock v:ext="edit" aspectratio="t"> </o:lock> </font> </v:shapetype> <v:shape id="_x0000_i1025" style="WIDTH: 21.75pt; HEIGHT: 18pt" type="#_x0000_t75" o:ole=""> <v:imagedata src="file:///C:\DOCUME~1\HSQ\LOCALS~1\Temp\msohtml1\01\clip_image001.wmz" o:title=""> </v:imagedata> </v:shape> </span> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">錛屼粠</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">CourseHierarchy.txt</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">澶撮儴寮濮嬫壂鎻忥紝鍏朵粬浠?/span> <i style="mso-bidi-font-style: normal"> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">i</font> </span> </i> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">涓哄厛淇鐨勮紼嬫瀯鎴?/span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <span style="POSITION: relative; TOP: 6pt; mso-text-raise: -6.0pt"> <v:shape id="_x0000_i1026" style="WIDTH: 21.75pt; HEIGHT: 18pt" type="#_x0000_t75" o:ole=""> <font face="Times New Roman"> <v:imagedata src="file:///C:\DOCUME~1\HSQ\LOCALS~1\Temp\msohtml1\01\clip_image001.wmz" o:title=""> </v:imagedata> </font> </v:shape> </span> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐨勫彸瀛愭爲銆傚姝や綆褰掓瀯閫犲嚭<span style="COLOR: red"><font color="#000000">璇劇▼浣撶郴浜屽弶鏍?/font></span>銆?/span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">姝ラ</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">1</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">錛氫粠鏂囦歡</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">CourseHierarchy.txt</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">鐢熸垚<b style="mso-bidi-font-weight: normal"><span style="COLOR: red"><font color="#000000">璇劇▼閾捐〃</font></span></b></span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">Course_Slist</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">錛堝弬鏁拌〃錛夈?/span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">姝ラ</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">2</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">錛氬皢鎸囬拡</span> <b style="mso-bidi-font-weight: normal"> <span lang="EN-US" style="FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt">CousreSystem_root</span> </b> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-hansi-font-family: 'Courier New'; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: 'Courier New'">鎸囧紩鐨?/span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">璇劇▼閾捐〃閫掑綊杞崲涓鴻紼嬩綋緋諱簩鍙夋爲<br /></span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <o:p> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">姝ラ</span> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <font face="Times New Roman">3</font> </span> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'">錛氬厛搴忚緭鍑轟簩鍙夋爲錛屼互楠岃瘉鐢熸垚鐨勪簩鍙夋爲鏄惁姝g‘<br /><strong>瀹炵幇浠g爜<br /></strong><font face="Arial"><strong>tree_binary.cpp</strong><br />// tree_binary.cpp : 瀹氫箟鎺у埗鍙板簲鐢ㄧ▼搴忕殑鍏ュ彛鐐廣?br />//<br />#pragma once</font></span> </o:p> </span> </p> <span lang="EN-US" style="mso-fareast-font-family: 妤蜂綋_GB2312"> <o:p> <span style="FONT-FAMILY: 妤蜂綋_GB2312; mso-ascii-font-family: 'Times New Roman'"> <font face="Arial"> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <br />#include <iostream><br />#include <tchar.h></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">//#include<fstream><br />//#include<iostream><br />//#include<cstdlib><br />#include"tree_binaryHF.h"<br />using namespace std;<br />int _tmain(int argc, _TCHAR* argv[])<br />{<br />聽char file_name[20]="CourseHierarchy.txt";<br />聽LinkList L;//閾捐〃鐨勫ご鎸囬拡<br />聽LinkList T;//鏍戠殑鏍?br />聽cout<<"\t鏈▼搴忕殑浣滅敤鏄粠鏂囦歡(鏂囦歡鍐呭鍙寜闇姹傛敼鍐?"<<endl<br />聽聽<<"聽聽聽聽聽聽聽 涓鍙栦俊鎭紝鏀懼埌閾捐〃涓紝鏈鍚庣敓鎴愪簩鍙夋爲錛?<<endl<br />聽聽<<"聽聽聽聽聽聽聽 鐒跺悗鍏堝簭涓簭錛屽悗緇亶鍘嗕簩鍙夋爲."<<endl;<br />聽InitList(L);<br />聽cout<<"璇誨嚭鐨勬枃浠跺唴瀹?"<<endl;<br />聽OpenFile(L,file_name);<br />聽cout<<"鐢熸垚閾捐〃鍚庣殑緇撴灉:"<<endl; <br />聽PrintLinkLIst(L);<br />聽聽聽 CreateBiTree(L,T,0);//鐢熸垚浜屽弶鏍?br />聽cout<<"鍏堝簭閬嶅巻浜屽弶鏍戠殑緇撴灉:";<br />聽PreOrder(T);<br />聽cout<<endl<<"涓簭閬嶅巻浜屽弶鏍戠殑緇撴灉:";<br />聽InOrder(T);<br />聽cout<<endl<<"鍚庡簭閬嶅巻浜屽弶鏍戠殑緇撴灉:";<br />聽聽聽 BackOrder(T);<br />聽cout<<endl;<br />聽return 0;<br />}</p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">聽</p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <br /> <strong>tree_binaryHF.h</strong> <br />#include"cao.hpp"<br />//*************************************//<br />//鎵撳紑鏂囦歡錛屽茍璇誨彇閲岄潰鐨勬墍鏈夊唴瀹?br />Status OpenFile(LinkList&L,char file_name[])//鐢變簬榪欓噷闇瑕佹妸鏁版嵁鎻掑叆閾捐〃涓?br />{<br />聽int CNum,CScore,PreScore;<br />聽ifstream in_stream;<br />聽in_stream.open(file_name);<br />聽if(in_stream.fail())//if the file is not opened successfully<br />聽{<br />聽聽cout<<"can't open the file of "<<file_name<<endl;<br />聽聽exit(0);<br />聽}<br />聽//i<br />聽cout<<"CNum"<<"\t"<<"PreScore"<<"\t"<<"CScore"<<endl;<br />聽while(in_stream>>CNum>>PreScore>>CScore)//璇誨彇涓変釜鏁版嵁(璇劇▼緙栫爜,瀛﹀垎,鍏堜慨璇?<br />聽{<br />聽聽cout<<CNum<<"\t"<<PreScore<<"\t"<<"\t"<<CScore<<endl;聽//鏀懼埌鑺傜偣涓?br />聽聽LinkInsert(L,CNum,PreScore,CScore);//insert the node to the linklist L<br />聽}<br />聽in_stream.close();<br />聽return OK;<br />}<br />Status InitList(LinkList &L)<br />{<br />聽L= (LinkList)malloc(sizeof(LNode));<br />聽if(!L)<br />聽聽return ERROR;<br />聽L->lchild=NULL;<br />聽L->rchild=NULL;<br />聽L->CNumber=0;<br />聽L->CScore=0;<br />聽L->PreCourse=0;<br />聽return OK;<br />}<br />Status LinkInsert(LinkList &L,Status CNum,Status PreCourse,Status CScore)//鎶婃柊寰楀埌鐨勭粨鐐規彃鍏ラ摼琛紝浠庡ご緇撶偣澶勬彃鍏?br />{<br />聽LinkList p;<br />聽p=(LinkList)malloc(sizeof(LNode));<br />聽if(!p)<br />聽聽return ERROR;<br />聽p->CNumber=CNum;<br />聽p->CScore=CScore;<br />聽p->PreCourse=PreCourse;<br />聽p->lchild=NULL;<br />聽p->rchild=L->rchild;<br />聽L->rchild=p;<br />聽return OK;<br />}<br />Status PrintLinkLIst(LinkList &L)//鎵撳嵃鏁翠釜閾捐〃錛屽彸鎸囬拡鎸囧悜鍚庣戶緇撶偣錛屽乏鎸囬拡絀?br />{<br />聽LinkList p;<br />聽p=L->rchild;<br />聽while(p)<br />聽{<br />聽聽cout<<p->CNumber<<"\t"<<p->PreCourse<<"\t"<<"\t"<<p->CScore<<endl;<br />聽聽p=p->rchild;<br />聽}<br />聽return OK;<br />}<br />Status CreateBiTree(LinkList &L,LinkList&T,Status c)<br />{<br />聽LinkList p;<br />聽//while(!EmptyLinkList(L))<br />聽//{<br />聽if(!(p=Serach(L,c)))<br />聽聽T=NULL;<br />聽else<br />聽{<br />聽聽T=p;//鐢熸垚鏍硅妭鐐?br />聽聽delet(L,c);//鍒犻櫎p緇撶偣<br />聽聽CreateBiTree(L,T->lchild,T->CNumber);//鏋勯犲乏瀛愭爲<br />聽聽CreateBiTree(L,T->rchild,T->PreCourse);//鏋勯犲彸瀛愭爲<br />聽}<br />聽//}<br />聽return OK;<br />}<br />LinkList Serach(LinkList &L,Status c)<br />{<br />聽LinkList head,next;<br />聽head=L;<br />聽next=head->rchild;<br />聽while(next&&(next->PreCourse!=c))<br />聽{<br />聽聽head=next;<br />聽聽next=next->rchild;<br />聽}<br />聽if(next==NULL)<br />聽聽return NULL;//娌℃湁鎵懼埌<br />聽else//鎵懼埌浜?br />聽聽return next;<br />}<br />void delet(LinkList &L,Status c)<br />{<br />聽LinkList head,next;<br />聽head=L;<br />聽next=head->rchild;<br />聽while(next&&(next->PreCourse!=c))<br />聽{<br />聽聽head=next;<br />聽聽next=next->rchild;<br />聽}<br />聽head->rchild=next->rchild;<br />聽//free(next);<br />}<br />Status EmptyLinkList(LinkList L)<br />{<br />聽if(L->rchild=NULL)<br />聽聽return OK;<br />聽else<br />聽聽return ERROR;<br />}<br />//鍏堝簭閬嶅巻鐨勯掑綊<br />void PreOrder(LinkList T)<br />{<br />聽if(T)<br />聽{<br />聽聽 //璁塊棶緇撶偣<br />聽 cout<<T->CNumber<<" ";<br />聽 PreOrder(T->lchild);聽聽 //閬嶅巻宸﹀瓙鏍?br />聽 PreOrder(T->rchild);聽聽 //閬嶅巻鍙沖瓙鏍?br />聽//cout<<endl;<br />聽}<br />}聽<br />//涓簭閬嶅巻鐨勯掑綊<br />void InOrder(LinkList T)<br />{<br />聽if(T)<br />聽{<br />聽 InOrder(T->lchild);聽聽 //閬嶅巻宸﹀瓙鏍?br />聽聽 //璁塊棶緇撶偣<br />聽 cout<<T->CNumber<<" ";<br />聽 InOrder(T->rchild);聽聽 //閬嶅巻鍙沖瓙鏍?br />聽}<br />}聽<br />//鍚庡簭閬嶅巻鐨勯掑綊<br />void BackOrder(LinkList T)<br />{<br />聽if(T)<br />聽{<br />聽 BackOrder(T->lchild);聽聽 //閬嶅巻宸﹀瓙鏍?br />聽 BackOrder(T->rchild);聽聽 //閬嶅巻鍙沖瓙鏍?br />聽 cout<<T->CNumber<<" ";<br />}<br />}聽</p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">聽</p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <br /> <strong>cao.hpp</strong> <br />#include<fstream><br />#include<iostream><br />#include<cstdlib><br />using namespace std;<br />typedef int Status;<br />#define OK聽聽 1<br />#define ERROR 0<br />typedef struct LNode聽聽聽聽聽聽聽聽聽聽聽聽 <br />{<br />聽struct LNode *lchild;<br />聽struct LNode *rchild;聽 <br />聽Status CNumber;<br />聽Status CScore;聽聽聽 <br />聽Status PreCourse;<br />}LNode,*LinkList;<br />Status OpenFile(LinkList&L,char file_name[]);<br />//鎵撳紑鏂囦歡錛屽茍涓旀彃鍏ヨ妭鐐?br />//*************************//<br />LinkInsert(LinkList &L,Status CNum,Status CScore,Status PreScore);<br />//insert the node to the linklist L<br />//*************************//<br />Status InitList(LinkList &L);//鍒濆鍖栭摼琛?br />//****************************************//<br />Status PrintLinkList(LinkList &L);//杈撳嚭閾捐〃<br />//********************************//<br />LinkList Serach(LinkList &L,Status c);//鏌ユ壘鑺傜偣<br />//*********************************************//<br />void delet(LinkList&L,Status c);//鍒犻櫎鑺傜偣<br />//*************************************//<br />Status EmptyLinkList(LinkList L);//媯鏌ラ摼琛ㄦ槸鍚︿負絀猴紙娌$敤鍒幫級 <br />//***********************************//<br />//鍏堝簭閬嶅巻浜屽弶鏍?br />void PreOrder(LinkList T);<br />//***********************************//<br />void InOrder(LinkList T);//涓簭閬嶅巻浜屽弶鏍?br />//*****************************//<br />void BackOrder(LinkList T);//鍚庣畫閬嶅巻浜屽弶鏍?br /><br /><strong>CourceSource.txt</strong><br />1聽2聽2<br />2聽0聽1<br />3聽0聽4<br />4聽2聽1<br />5聽7聽1<br />6聽7聽6<br />7聽2聽2<br /></p> </font> </span> </o:p> </span> <br /> <font face="Arial"> <strong>榪愯緇撴灉<br /></strong>鍏堝簭閬嶅巻浜屽弶鏍戯細3銆2銆7銆6銆5銆4銆1<br />涓簭閬嶅巻浜屽弶鏍戯細3銆6銆5銆7銆4銆1銆2<br />鍚庡簭閬嶅巻浜屽弶鏍戯細5銆6銆1銆4銆7銆2銆3</font> <img src ="http://www.tkk7.com/matthew2006/aggbug/77902.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-10-29 14:57 <a href="http://www.tkk7.com/matthew2006/archive/2006/10/29/77902.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏍堝拰闃熺殑搴旂敤錛嶉瓟鐜嬭璦瑙i噴http://www.tkk7.com/matthew2006/archive/2006/10/14/75167.htmlmatthewmatthewSat, 14 Oct 2006 11:18:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/10/14/75167.htmlhttp://www.tkk7.com/matthew2006/comments/75167.htmlhttp://www.tkk7.com/matthew2006/archive/2006/10/14/75167.html#Feedback4http://www.tkk7.com/matthew2006/comments/commentRss/75167.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/75167.html 闂鎻忚堪錛?/strong>

聽聽聽 璁捐騫跺疄鐜伴瓟鐜嬭璦鐨勮В閲婂櫒錛屽叿浣撹姹傚涓嬶細澶у啓瀛楁瘝琛ㄧず欖旂帇璇█鐨勮瘝姹囷紱灝忓啓瀛楁瘝琛ㄧず浜虹殑璇嶆眹璇█錛涢瓟鐜嬭璦涓彲鍖呭惈鎷彿銆?/font>

聽聽聽 濡傦細鎴戜滑鏈夐瓟鐜嬭璦鐨勮В閲婅鍒欙細B錛?gt;tAdA錛汚->sae錛涘垯欖旂帇璇█ B(ehnxgz)B瑙i噴鎴恡saedsaeezegexenehetsaedsae銆?br />
瀹炵幇浠g爜濡備笅錛?br />
#include<stdlib.h>
#include<stdio.h>
#define STACK_INIT_SIZE 100 //瀛樺偍絀洪棿鍒濆鍒嗛厤閲?br />#define STACK_INCREMENT聽 10聽 //瀛樺偍絀洪棿鍒嗛厤澧為噺
#define OVERFLOW聽聽聽聽聽聽聽聽聽 1
#define OK聽聽聽聽聽聽聽聽聽 1
#define ERROR聽聽聽聽聽 0
#define TRUE聽聽聽聽聽聽聽 1
#define FALSE聽聽聽聽聽聽 0
typedef char聽聽聽聽聽 SElemType;
typedef char聽聽聽聽聽 QElemType;
typedef int聽聽聽聽 Status;
typedef struct{
聽SElemType *base;聽聽聽聽聽聽聽聽聽聽聽 //鏍堝熀鍧
SElemType *top;聽聽聽聽聽聽聽聽聽聽聽聽 //鏍堥《鍦板潃
聽int stacksize;
}SqStack;
typedef struct QNode{
聽QElemType data;
聽struct QNode *next;
}QNode,*QueuePtr;
typedef struct{
聽QueuePtr front;聽聽 //闃熷ご鎸囬拡
聽QueuePtr rear;聽聽聽 //闃熷熬鎸囬拡
}LinkQueue;
Status InitStack(SqStack &S)
//鏋勯犱竴涓┖鏍?br />{
聽S.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(char));
聽if(!S.base)
聽聽exit (OVERFLOW);//瀛樺偍鍗曞厓鍒嗛厤澶辮觸
聽S.top=S.base;
聽S.stacksize=STACK_INIT_SIZE;
聽return OK;
}
Status Push(SqStack &S,SElemType e)
//鎻掑叆鍏冪礌e鏍堥《鍗曞厓
{
聽if(S.top-S.base>=S.stacksize)
聽{//鏍堟弧錛岃拷鍔犲瓨鍌ㄧ┖闂?br />聽聽S.base=(SElemType *)realloc(S.base,(S.stacksize+STACK_INCREMENT)*sizeof(char));
聽if(!S.base)
聽聽exit (OVERFLOW);//瀛樺偍鍗曞厓鍒嗛厤澶辮觸
聽S.top=S.base+S.stacksize;
聽S.stacksize+=STACK_INCREMENT;
聽}
聽*(S.top)=e;
聽S.top++;
聽return OK;
}
Status Pop(SqStack &S,SElemType& e)
//鑻ユ爤涓嶄負絀猴紝鍒欏垹闄鐨勬爤欏跺崟鍏冿紝鐢╡榪斿洖鍏跺?br />{
聽if(S.base==S.top)
聽聽return ERROR;
聽S.top--;
聽e=*(S.top);
聽return OK;
}
Status StackEmpty(SqStack S)
{
聽if(S.base==S.top)
聽聽return 0;
聽else
聽聽return 1;
}

Status InitQueue(LinkQueue &Q)
//鏋勯犱竴涓┖闃熷垪Q
{
聽Q.front=Q.rear=(QueuePtr)malloc(sizeof (QNode));
聽if(!Q.front)
聽聽exit (OVERFLOW);
聽Q.front->next=NULL;
聽return OK;
}
Status EnQueue (LinkQueue&Q,QElemType e)
//鎻掑叆鍏冪礌e涓篞鐨勬柊鐨勯槦灝懼厓绱?br />{
聽QueuePtr p;
聽p=(QueuePtr)malloc(sizeof (QNode));
聽p->data=e;
聽p->next=NULL;
聽Q.rear->next=p;
聽Q.rear=p;
聽return OK;
}
Status DeQueue (LinkQueue &Q,QElemType &e)
//鑻ラ槦鍒椾笉絀猴紝鍒欏垹闄鐨勯槦澶村厓绱狅紝鐢╡榪斿洖鍏跺鹼紝騫惰繑鍥濷K;
//鍚﹀垯榪斿洖ERROR
{
聽QueuePtr p;
聽if(Q.front==Q.rear)
聽聽return ERROR;
p=Q.front->next;
聽e=p->data;
聽Q.front->next=p->next;
聽if(p==Q.rear)
聽聽Q.rear=Q.front;
聽free(p);
聽return OK;
}
Status QueueEmpty(LinkQueue Q)
//鑻ラ槦鍒桻涓虹┖闃熷垪,鍒欒繑鍥濼RUE錛屽惁鍒欒繑鍥濬ALSE
{
聽if(Q.rear==Q.front)
聽聽return FALSE;
聽else
聽聽return TRUE;
}
void InStack(char fiend[],SqStack &S)
{
聽int m,i=0;
聽for(;fiend[i]!='\0';i++);//璁$畻fiend涓湁澶氬皯
聽for(m=i-1;m>=0;m--)
聽聽Push(S,fiend[m]);
}
void main()
{
聽char e,c,d;
聽SqStack S,zhan;
聽LinkQueue Q;
聽聽 InitQueue(Q);
聽char聽 mowang[]="B(ehnxgz)B";
聽printf("浣犳兂瑕佽В閲婄殑欖旂帇璇█涓猴細%s\n",mowang);
聽聽聽 char聽 B[]="tAdA";
聽InitStack(S);
聽InitStack(zhan);
聽InStack(mowang,S);//鍏ㄩ儴鍘嬭繘鏍堜腑
聽while(StackEmpty(S))//鍦ㄦ爤涓嶄負絀虹殑鎯呭喌涓?br />聽{
聽聽Pop(S,e);
聽聽if(e=='B')
聽聽InStack(B,zhan);
聽聽else
if(e=='(')//濡傛灉涓哄彸鎷彿錛屽垯杈撳嚭鎷彿涓墍鏈夊唴瀹?br />聽聽聽{
聽聽聽聽while(Pop(S,e)&&e!=')')//褰撲負宸︽嫭鍙鋒椂鍋滄
聽聽聽聽{
聽聽聽聽聽if(e!=')')
聽聽聽聽聽EnQueue (Q,e);
聽聽聽聽}
聽聽聽聽聽DeQueue (Q,c);//璇誨嚭闃熷垪涓涓涓厓绱?br />聽聽聽聽while(QueueEmpty(Q))
聽聽聽聽{
聽聽聽聽聽DeQueue (Q,d);//鍙栧嚭鍏冪礌
聽聽聽聽聽Push(zhan,c);
聽聽聽聽聽Push(zhan,d);
聽聽聽聽}
聽聽聽聽Push(zhan,c);//鍐嶆鍘嬪叆絎竴涓厓绱?br />聽聽聽//聽Pop(S,e);//鍘繪帀宸︽嫭鍙?br />聽聽聽}

聽}
聽printf("\n瑙i噴鐨勭粨鏋滀負:聽 ");
聽聽聽 while(StackEmpty(zhan))//鍦ㄦ爤涓嶄負絀虹殑鎯呭喌涓?br />聽{

聽聽Pop(zhan,c);
聽聽if(c=='A')
printf("sae");
聽聽聽聽聽聽聽 else
聽聽聽聽 printf("%c",c);
聽聽}
聽聽printf("\n");
}



matthew 2006-10-14 19:18 鍙戣〃璇勮
]]>
鏁版嵁緇撴瀯涔嬬嚎鎬ц〃錛?涓鍏冪█鐤忓欏瑰紡璁$畻鍣?/title><link>http://www.tkk7.com/matthew2006/archive/2006/10/04/73393.html</link><dc:creator>matthew</dc:creator><author>matthew</author><pubDate>Wed, 04 Oct 2006 08:18:00 GMT</pubDate><guid>http://www.tkk7.com/matthew2006/archive/2006/10/04/73393.html</guid><wfw:comment>http://www.tkk7.com/matthew2006/comments/73393.html</wfw:comment><comments>http://www.tkk7.com/matthew2006/archive/2006/10/04/73393.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/matthew2006/comments/commentRss/73393.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/matthew2006/services/trackbacks/73393.html</trackback:ping><description><![CDATA[ <p> <strong>瑕佹眰錛?br />1聽 杈撳叆騫跺緩绔嬪欏瑰紡<br />2聽 杈撳嚭澶氶」寮忥紝杈撳嚭褰㈠紡澶栦負鏁存暟搴忓垪錛歝1,e1;c2,e2;.......cn,en;鍏朵腑n涓哄欏瑰紡鐨勯」鏁幫紝ci鍜宔i鍒嗗埆涓虹i欏圭殑緋繪暟鍜屾寚鏁幫紝搴忓垪鎸夋寚鏁伴檷搴忔帓鍒?br />3聽 澶氶」寮廰鍜宐鐩稿姞錛屽緩绔嬪欏瑰紡a+b<br />4聽 澶氶」寮廰鍜宐鐩稿噺錛屽緩绔嬪欏瑰紡a-b<br />浠g爜濡備笅錛?br /></strong>#include<stdio.h><br />#include<malloc.h><br />#define MAX 20聽 //澶氶」寮忔渶澶氶」鏁?br />typedef struct聽 //瀹氫箟瀛樻斁澶氶」寮忕殑鏁扮粍綾誨瀷<br />{<br />聽 float coef;聽聽 //緋繪暟<br />聽 int exp;聽聽聽聽聽 //鎸囨暟<br />}PolyArray[MAX];<br />typedef struct pnode聽 //瀹氫箟鍗曢摼琛ㄧ粨鐐圭被鍨?br />{<br />聽 float coef;聽聽聽聽聽聽聽聽 //緋繪暟<br />聽 int exp;聽聽聽聽聽聽聽聽聽聽聽 //鎸囨暟<br />聽 struct pnode *next;<br />}PolyNode; </p> <p>void DispPoly(PolyNode *L)聽 //杈撳嚭澶氶」寮?br />{<br />聽PolyNode *p=L->next;<br />聽while (p!=NULL)<br />聽{<br />聽 printf("%g,%d;",p->coef,p->exp);<br />聽 p=p->next;<br />聽}<br />聽printf("\n");<br />}<br />void CreateListR(PolyNode * &L,PolyArray a,int n)聽聽聽 //灝炬彃鍏ユ硶寤鴻〃<br />{<br />聽PolyNode *s,*r;int i;<br />聽L=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽聽聽 //鍒涘緩澶寸粨鐐?br />聽L->next=NULL;<br />//聽L->exp=n;<br />// printf("%d\n",L->exp);<br />聽r=L;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //r濮嬬粓鎸囧悜緇堢緇撶偣錛屽紑濮嬫椂鎸囧悜澶寸粨鐐?br />聽聽for(i=0;i<n;i++)<br />聽聽{<br />聽聽聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽 //鍒涘緩鏂扮粨鐐?br />聽聽聽 s->coef=a[i].coef;<br />聽聽聽 s->exp=a[i].exp;<br />聽聽聽 r->next=s;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //灝?s鎻掑叆*r涔嬪悗<br />聽聽聽 r=s;<br />聽聽}<br />聽聽r->next=NULL;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //灝嗙粓绔粨鐐筺ext鍩熺疆涓篘ULL<br />}<br />void Sort(PolyNode * &head)聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //鎸塭xp鍩熺殑鍊奸掑噺鎺掑簭<br />{<br />聽 PolyNode *p=head->next,*q,*r;<br />聽 if(p!=NULL)聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //褰撳師鍗曢摼琛ㄤ笉涓虹┖鏃?br />聽 {<br />聽聽 r=p->next;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //r淇濆瓨*p緇撶偣鍚庣戶緇撶偣鐨勬寚閽?br />聽聽 p->next=NULL;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //鏋勯犲彧鍚竴涓暟鎹粨鐐圭殑鏈夊簭琛?br />聽聽 p=r;<br />聽聽 while(p!=NULL)<br />聽聽 {<br />聽聽聽聽 r=p->next;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //r淇濆瓨*p緇撶偣鍚庣戶緇撶偣鐨勬寚閽?br />聽 q=head;<br />聽 while(q->next!=NULL && q->next->exp>p->exp)<br />聽聽 q=q->next;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //鍦ㄦ湁搴忚〃涓壘鎻掑叆*p鐨勫墠椹辯粨鐐?q<br />聽 p->next=q->next;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //灝?p鎻掑叆鍒?q涔嬪悗<br />聽 q->next=p;<br />聽 p=r;<br />聽聽 }<br />聽 }<br />}<br />void Add(PolyNode *ha,PolyNode *hb,PolyNode *&hc)//姹備袱涓湁搴忚〃鐨勫茍<br />{<br />聽 PolyNode *pa=ha->next,*pb=hb->next,*s,*tc;<br />聽 float c;<br />聽 hc=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽聽聽聽 //鍒涘緩澶寸粨鐐?br />聽 tc=hc;<br />聽 while(pa!=NULL && pb!=NULL)<br />聽 {<br />聽聽聽 if(pa->exp>pb->exp)<br />聽{<br />聽聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽 //澶嶅埗緇撶偣<br />聽聽 s->exp=pa->exp;s->coef=pa->coef;<br />聽聽 tc->next=s;tc=s;<br />聽聽 pa=pa->next;<br />聽}<br />聽else if(pa->exp<pb->exp)<br />聽{<br />聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽聽聽聽 //澶嶅埗緇撶偣<br />聽 s->exp=pb->exp;s->coef=pb->coef;<br />聽 tc->next=s;tc=s;<br />聽 pb=pb->next;<br />聽}<br />聽else聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //pa->exp=pb->exp鏃?br />聽{<br />聽c=pa->coef+pb->coef;<br />聽if(c!=0)聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //緋繪暟涔嬪拰涓嶄負0鏃跺垱寤烘柊緇撶偣<br />聽{<br />聽聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽 <br />聽聽 s->exp=pa->exp;s->coef=c;<br />聽聽 tc->next=s;tc=s;<br />聽}<br />聽pa=pa->next;<br />聽pb=pb->next;<br />聽} </p> <p>聽 }<br />聽 if(pb!=NULL)聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //澶嶅埗浣欎笅緇撶偣<br />聽聽 pa=pb;<br />聽 while(pa!=NULL)<br />聽 {<br />聽聽聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽聽聽聽 //澶嶅埗緇撶偣<br />聽s->exp=pa->exp;s->coef=pa->coef;<br />聽tc->next=s;tc=s;<br />聽pa=pa->next;<br />聽 }<br />聽 tc->next=NULL;<br />} </p> <p>void Subs(PolyNode *ha,PolyNode *hb,PolyNode *&hc)聽聽 //姹備袱涓湁搴忚〃鐨勫樊<br />{<br />聽 PolyNode *pa=ha->next,*pb=hb->next,*s,*tc;<br />聽 float c;<br />聽 hc=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽聽聽聽 //鍒涘緩澶寸粨鐐?br />聽 tc=hc;<br />聽 while(pa!=NULL && pb!=NULL)<br />聽 {<br />聽聽聽 if(pa->exp>pb->exp)<br />聽{<br />聽聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽 //澶嶅埗緇撶偣<br />聽聽 s->exp=pa->exp;s->coef=pa->coef;<br />聽聽 tc->next=s;tc=s;<br />聽聽 pa=pa->next;<br />聽}<br />聽else if(pa->exp<pb->exp)<br />聽{<br />聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽聽聽聽 //澶嶅埗緇撶偣<br />聽 s->exp=pb->exp;s->coef=-pb->coef;聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //濡傛灉鍓嶄釜澶氶」寮忎腑鐨勬寚鏁板皬浜庡悗涓欏瑰紡鎸囨暟鍔犱笂璐熷彿<br />聽 tc->next=s;tc=s;<br />聽 pb=pb->next;<br />聽}<br />聽else聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //pa->exp=pb->exp鏃?br />聽{<br />聽c=pa->coef-pb->coef;<br />聽if(c!=0)聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //緋繪暟涔嬪樊涓嶄負0鏃跺垱寤烘柊緇撶偣<br />聽{<br />聽聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽 <br />聽聽 s->exp=pa->exp;s->coef=c;<br />聽聽 tc->next=s;tc=s;<br />聽}<br />聽pa=pa->next;<br />聽pb=pb->next;<br />聽} </p> <p>聽 }<br />聽 if(pb!=NULL)聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 //澶嶅埗浣欎笅緇撶偣<br />聽聽 pa=pb;<br />聽 while(pa!=NULL)<br />聽 {<br />聽聽聽 s=(PolyNode *)malloc(sizeof(PolyNode));聽聽聽聽聽聽聽聽聽聽 //澶嶅埗緇撶偣<br />聽s->exp=pa->exp;s->coef=pa->coef;<br />聽tc->next=s;tc=s;<br />聽pa=pa->next;<br />聽 }<br />聽 tc->next=NULL;<br />}<br />void main()<br />{<br />聽聽 PolyNode *ha,*hb,*hc;<br />聽聽 //PolyArray a={{1.2,0},{2.5,1},{3.2,3},{-2.5,5}};<br />聽聽 //PolyArray b={{-1.2,0},{2.5,1},{3.2,3},{2.5,5},{5.4,10}};<br />聽聽 int m=4,n=5;<br />聽聽 PolyArray a,b;<br />聽聽 for(int i=0;i<m;i++)<br />聽聽 {<br />聽聽聽聽 printf("璇瘋緭鍏澶氶」寮忎腑絎?d欏圭殑緋繪暟鍜屾寚鏁?,i);<br />聽 scanf("%f%d",&a[i].coef,&a[i].exp);<br />聽聽 }<br />聽 <br />聽聽聽 for(int j=0;j<n;j++)<br />聽聽 {<br />聽聽聽聽 printf("璇瘋緭鍏澶氶」寮忎腑絎?d欏圭殑緋繪暟鍜屾寚鏁?,j);<br />聽 scanf("%f%d",&b[j].coef,&b[j].exp);<br />聽聽 } </p> <p>聽聽 CreateListR(ha,a,4);<br />聽聽 CreateListR(hb,b,5);<br />聽聽 printf("鍘熸潵A:\n");DispPoly(ha);<br />聽聽 printf("鍘熸潵B:\n");DispPoly(hb); </p> <p>聽聽 Sort(ha);<br />聽聽 Sort(hb);<br />聽聽 printf("鎺掑簭鍚嶢:\n");DispPoly(ha);<br />聽聽 printf("鎺掑簭鍚嶣:\n");DispPoly(hb); </p> <p>聽聽 Add(ha,hb,hc);<br />聽聽 printf("鐩稿姞鍚?\n");DispPoly(hc);<br />聽聽 Subs(ha,hb,hc);<br />聽聽 printf("鐩稿噺鍚?\n");DispPoly(hc);<br />} </p> <img src ="http://www.tkk7.com/matthew2006/aggbug/73393.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/matthew2006/" target="_blank">matthew</a> 2006-10-04 16:18 <a href="http://www.tkk7.com/matthew2006/archive/2006/10/04/73393.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鏁版嵁緇撴瀯涔嬫娊璞℃暟鎹被鍨嬶紞澶嶆暟鍥涘垯榪愮畻http://www.tkk7.com/matthew2006/archive/2006/09/25/71811.htmlmatthewmatthewMon, 25 Sep 2006 10:52:00 GMThttp://www.tkk7.com/matthew2006/archive/2006/09/25/71811.htmlhttp://www.tkk7.com/matthew2006/comments/71811.htmlhttp://www.tkk7.com/matthew2006/archive/2006/09/25/71811.html#Feedback0http://www.tkk7.com/matthew2006/comments/commentRss/71811.htmlhttp://www.tkk7.com/matthew2006/services/trackbacks/71811.html [ 澶嶆暟 ADT 鐨勬弿榪?/span> ]
ADT complex{
銆銆銆 鏁版嵁瀵硅薄錛?/span> D={ c1,c2 c1,c2 鈭?/span> FloatSet }
銆銆銆 鏁版嵁鍏崇郴錛?/span> R={ <c1,c2> c1 c2 銆銆 }
銆銆銆 鍩烘湰鎿嶄綔錛氬垱寤轟竴涓鏁般銆銆銆 creat(a);
銆銆銆銆銆銆銆銆 杈撳嚭涓涓鏁般銆銆銆 outputc(a);
銆銆銆銆銆銆銆銆 姹備袱涓鏁扮浉鍔犱箣鍜屻 add(a,b);
銆銆銆銆銆銆銆銆 姹備袱涓鏁扮浉鍑忎箣宸 sub(a,b);
銆銆銆銆銆銆銆銆 姹備袱涓鏁扮浉涔樹箣縐 chengji(a,b);
銆銆銆銆銆銆銆銆 絳夌瓑 ;
} ADT complex;
瀹炵幇澶嶆暟 ADT 鍙互浣跨敤闈㈠悜榪囩▼鐨勭▼搴忚璁℃柟娉曪紝涔熷彲浠ョ敤闈㈠悜瀵硅薄紼嬪簭璁捐鏂規硶銆?br />[澶嶆暟ADT瀹炵幇鐨勯潰鍚戣繃紼?/span>C璇█婧愮▼搴?/span>]-complex.h
#include <stdio.h>
#include <stdlib.h>
typedef struct Complex
{
聽float聽real;聽
聽float聽image;
}Complex;

void CreatComplex(Complex& c,float a,float b);

void AddComplex(Complex& sum,Complex c1,Complex c2 );

void Subtract_C(Complex& Sub,Complex c1,Complex c2 );

void Multiple_C(Complex& product,Complex c1,Complex c2 );

void Print_C(Complex c);

void CreatComplex(Complex& c,float a,float b)
{
聽c.real = a;
聽c.image = b;
}

void AddComplex(Complex& sum,Complex c1,Complex c2)
{
聽sum.real = c1.real + c2.real ;
聽sum.image = c1.image聽 + c2.image聽 ;
}


void聽 Subtract_C(Complex& Sub,Complex c1,Complex c2 )
{
聽Sub.real = c1.real -c2.real ;
聽Sub.image = c1.image聽- c2.image ;
}

void Multiple_C(Complex& product,Complex c1,Complex c2 )
{
聽product.real = c1.real * c2.real - c1.image * c2.image ;

聽product.image = c1.real * c2.image + c1.image * c2.real ;
}


void Print_C(Complex c)
{
聽if (c.image == 0.0)
聽聽printf("%5.2f\n",c.real );
聽else
聽聽printf("%5.2f+%5.2fi\n",c.real ,c.image );
聽if(c.real==0.0)
聽聽printf("%5.2fi\n",c.image);
}
complex.cpp浠g爜錛?br />#include "complex.h"
#include <stdio.h>
void main()
{
聽float a,b,c,d;
聽Complex聽聽c1,c2,sum,Sub,Prod;

聽scanf("%f%f%f%f",&a,&b,&c,&d);
聽聽聽
聽CreatComplex(c1,a,b);

聽Print_C(c1);

聽CreatComplex(c2,c,d);
聽Print_C(c2);

聽AddComplex(sum,c1,c2);
聽Print_C(sum);

聽Subtract_C(Sub,c1,c2);
聽Print_C(Sub);

聽Multiple_C(Prod,c1,c2);
聽Print_C(Prod);
}



matthew 2006-09-25 18:52 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 你是我的城池营垒免费看| 亚洲国产电影av在线网址| 成年女人喷潮毛片免费播放| 日本免费高清视频| 亚洲一区二区三区夜色| 亚洲视频中文字幕在线| 日韩精品无码免费专区午夜| 97国免费在线视频| 亚洲一区二区三区免费在线观看 | 亚洲中文字幕无码一区 | 日韩在线视精品在亚洲| 久久激情亚洲精品无码?V| 99久热只有精品视频免费观看17| 亚洲日韩精品无码专区加勒比| 亚洲午夜成人精品电影在线观看| 久草免费手机视频| 免费一区二区无码视频在线播放| 亚洲福利视频网址| 99久久亚洲精品无码毛片| 亚洲精品99久久久久中文字幕 | 曰批视频免费40分钟试看天天| 最近的免费中文字幕视频 | 在线观看免费国产视频| 亚洲国产精品成人久久蜜臀| 亚洲AV无码码潮喷在线观看| 亚洲真人无码永久在线观看| 9久久免费国产精品特黄| 免费成人激情视频| 亚洲av无码成人精品区| 久久精品国产亚洲AV麻豆王友容| 亚洲中文字幕无码av永久| 中文字幕永久免费视频| 成人性生免费视频| 国产成人亚洲精品狼色在线| 亚洲国产成a人v在线观看| 国产日韩精品无码区免费专区国产| 成人免费AA片在线观看| 亚洲国产美女精品久久久久| 亚洲午夜无码片在线观看影院猛| 亚洲国语精品自产拍在线观看| 午夜亚洲WWW湿好爽|