数据结构(C++)(第07章.ppt

4.拓扑排序的算法实现 //本算法中采用图7-34所示的AOV网作示范 #includeiostream.h typedef int elemtype; const int n=5;//n表示图中顶点数 const int e=6;//e表示图中弧的数目 class link { public: elemtype data;link *next; }; class node { public: link a[n+1]; void creatlink3(node g ); void topsort (node g ); } ; void node::creatlink3( node g)//建立带入度的邻接表 { int i,j,k ; link *s ; for(i=1; i=n;i++)//建立邻接表头结点 { g.a[i].data=0;//入度值为0g.a[i].next=NULL; } for(k=1; k=e;k++) { cout请输入一条弧:; cinij ;//输入一条弧 i,j coutendl; s=new link;//申请一个动态存储单元 s-data=j ; s-next=g.a[i].next ; g.a[i].next=s ; g.a[j].data++;//入度加1

文档评论(0)

1亿VIP精品文档

相关文档