📄 ldigraph.cpp
字号:
// test linked adjacency list directed graph class
#include <iostream.h>
#include "ldigraph.h"
void main(void)
{
LinkedDigraph G(4);
cout << "Edges = " << G.Edges() << endl;
G.Add(2,4).Add(1,3).Add(2,1).Add(1,4).Add(4,2);
cout << "The graph is" << endl;
G.Output();
G.Delete(2,4);
cout << "The graph after deleting <2,4> is" << endl;
G.Output();
try {G.Delete(3,4);
cout << "Edge <3,4> has been deleted" << endl;}
catch (...)
{cout << "Deletion of <3,4> failed" << endl;}
cout << "Exist(3,1) = " << G.Exist(3,1) << endl;
cout << "InDegree(3) = " << G.InDegree(3) << endl;
cout << "OutDegree(1) = " << G.OutDegree(1) << endl;
cout << "Edges = " << G.Edges() << endl;
LinkedDigraph L(7);
int reach[8];
int n = 7;
cout << "enter number of edges in weighted digraph" << endl;
int e, u, v;
cin >> e;
for (int i = 1; i <= e; i++)
{
cout << "enter edge " << i << endl;
cin >> u >> v;
L.Add(u,v);
}
for (i =1 ; i <= n; i++)
reach[i] = 0;
cout << "Doing bfs from vertex 1 labeling 1" << endl;
L.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 + -