資源簡介
實現圖的判斷,圖的拓撲排序,單源最短路徑,求最大生成樹等主要算法!??!

代碼片段和文件信息
#include
#include
#include
//====================================================================
const?int?MaxVertices=10;
const?int?MaxWeight=32767;
class?AdjMGraph
{
private:
char?Vertices[MaxVertices][10];//頂到信息的數組
int?cost[MaxVertices][MaxVertices];//邊的權信息的矩陣
int?numEnumVv0;//當前的邊數,頂點數,源點號
int?dist[MaxVertices]pre[MaxVertices];//距離,路徑的數組
int?flag;//圖的類型
public:
AdjMGraph();
void?CreatG(int?nint?e);
void?PrintOut();?//輸出鄰接矩陣
void?dijkstra();?//迪杰斯特拉求最短路徑
void?disply();???//輸出最短路徑以及長度
void?JudgeG();???//判斷函數
void?TopSort();??//拓撲排序
};
//==================================================================
AdjMGraph::AdjMGraph()
{
int?ij;
for(i=0;i {
dist[i]=0;pre[i]=0;
}
for(i=0;i {
for(j=0;j if(i==j)
cost[i][j]=0;
else
cost[i][j]=MaxWeight;
}
numE=0;
numV=0;
}
//=======================================================================
void?AdjMGraph::CreatG(int?nint?e)
{
int?vivjw;
numE=e;
numV=n;
cout<<“輸入點的信息:“;
for(int?i=0;i {
cout<<“\n“< cin>>Vertices[i];
}
char?k;
do{
cout<<“\n?輸入邊的信息(vivjw):?“;
cin>>vi>>vj>>w;
cost[vi-1][vj-1]=w;
cout<<“是否繼續(Y/N):“;
cin>>k;
}while(k==‘Y‘);
}
//==================================================================================
void?AdjMGraph::JudgeG()
{
int?ij;
bool?x=1y=0;
for(i=0;i {
do{
for(j=0;j {
if(i!=j)
{
if((cost[i][j]!=cost[j][i])||(cost[i][j]==MaxWeight)||(cost[j][i]==MaxWeight))//該圖有向
{
flag=1;
x=0;
break;
}
if(cost[i][j]==cost[j][i])????????????????????//該圖無向
{
flag=2;
x=0;
}
}
}
}while(x==1);
break;
}
switch(flag)
{
case?1:
{
for(i=0;i {
if(cost[i][i]!=0)
{y=0;break;}
else
y=1;
}
if(y==1)
cout<<“該圖為有向無環圖“< else
cout<<“該圖為有向帶環圖“< }
break;
case?2:
{
for(i=0;i {
if(cost[i][i]!=0)
{y=0;break;}
else
y=1;
}
if(y==1)
cout<<“該圖為無向圖“< else
cout<<“該圖為無向帶環圖“< }
break;
}
}
//==========================================================================================
void?AdjMGraph::PrintOut()
{
int?j;
cout<<“\n?輸出頂點的信息:\n“;
for(int?i=0;i cout< cout<<“\n?輸出鄰接矩陣:?“;
for(i=0;i {
cout<<“\n“< for(j=0;j cout< cout< }
}
//=================================================================================================
void?AdjMGraph::dijkstra()??????????????//求n各頂點,鄰接矩陣為cost,從源點i0到個頂點的最短路徑
{ ????????????????//dist記載從源點到其余各頂點的最短路徑長度
????int?iuminjv;????????????????????//pre記載
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????180868??2010-07-09?12:12??0810569_05_趙連云\0810569_05_趙連云.docx
?????文件?????217156??2010-06-11?21:30??0810569_05_趙連云\Graph\Debug\Grahp.exe
?????文件??????23778??2010-06-11?21:30??0810569_05_趙連云\Graph\Debug\Grahp.obj
?????文件?????541696??2010-06-11?21:30??0810569_05_趙連云\Graph\Debug\Grahp.pdb
?????文件?????217132??2010-06-08?22:25??0810569_05_趙連云\Graph\Debug\Graph.exe
?????文件?????517120??2010-06-08?22:25??0810569_05_趙連云\Graph\Debug\Graph.pdb
?????文件??????69632??2010-06-11?21:30??0810569_05_趙連云\Graph\Debug\vc60.pdb
?????文件???????6066??2010-06-11?21:27??0810569_05_趙連云\Graph\Grahp.cpp
?????文件???????3389??2010-06-08?22:28??0810569_05_趙連云\Graph\Grahp.dsp
?????文件????????518??2010-06-08?23:16??0810569_05_趙連云\Graph\Grahp.dsw
?????文件??????50176??2010-06-11?21:38??0810569_05_趙連云\Graph\Grahp.ncb
?????文件??????48640??2010-06-11?21:38??0810569_05_趙連云\Graph\Grahp.opt
?????文件????????741??2010-06-11?21:30??0810569_05_趙連云\Graph\Grahp.plg
?????目錄??????????0??2010-09-05?11:41??0810569_05_趙連云\Graph\Debug
?????目錄??????????0??2010-07-29?09:01??0810569_05_趙連云\Graph
?????目錄??????????0??2010-07-29?09:01??0810569_05_趙連云
-----------?---------??----------?-----??----
??????????????1876912????????????????????16
- 上一篇:stm32 外部上升沿觸發ADC采集
- 下一篇:客戶關系管理系統.rar
評論
共有 條評論