📄 lwdgraph.cpp
字号:
// test of linked adjacency list weighted digraph class
#include <iostream.h>
#include "lwdgraph.h"
void main(void)
{
LinkedWDigraph<int> L(4);
cout << "Edges = " << L.Edges() << endl;
L.Add(2,4,1).Add(1,3,2).Add(2,1,3).Add(1,4,4).Add(4,2,5);
cout << "The graph is" << endl;
L.Output();
L.Delete(2,1);
cout << "The graph after deleting <2,1> is" << endl;
L.Output();
cout << "Exist(3,1) = " << L.Exist(3,1) << endl;
cout << "InDegree(3) = " << L.InDegree(3) << endl;
cout << "OutDegree(1) = " << L.OutDegree(1) << endl;
cout << "Edges = " << L.Edges() << endl;
int i=1,j,c;
L.InitializePos();
try
{
L.First(i,j,c);
L.DeactivatePos();
cout<<i<<"->"<<j<<' '<<c<<endl;
}
catch(...)
{
cout<<"Failed!"<<endl;
}
LinkedWDigraph<int> G(7);
int reach[8];
int n = 7;
cout << "enter number of edges in weighted digraph" << endl;
int e, u, v, w;
cin >> e;
for (i = 1; i <= e; i++) {
cout << "enter edge " << i << endl;
cin >> u >> v >> w;
G.Add(u,v,w);}
for (i =1 ; i <= n; i++)
reach[i] = 0;
cout << "Doing bfs from vertex 1 labeling 1" << endl;
G.BFS(1, reach, 2);
cout << "Reached values for vertices are" << endl;
for (i = 1; i <= n; i++)
cout << reach[i] << ' ';
cout << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -