姑且先写了非递归的BFS与DFS, 以后再补上递归算法与拓扑排序吧
using System;
using System.Collections.Generic;
namespace DataStructurePractice
{
//邻接表存储的有向图
//造轮子, 手动链表实现
//使用数组代替List
//本例中顶点标识暂定为string型
class AdjListGraph
{
public ALGVertexNode[] NodeArray {
get; }
private int count;
public AdjListGraph(int nodeNums)
{
this.NodeArray = new ALGVertexNode[nodeNums];
this.count = 0;
}
public ALGVertexNode FindNode(string name)
{
for (int i = 0; i < count; i++)
{
if (NodeArray[i].Name == name)
{
return NodeArray[i];
}
}
throw new Exception();
}
public int FindNodeIndex(string name)
{
for (int i = 0; i < count; i++)
{
if (NodeArray[i].Name == name)
{
return i;
}
}
throw