// //编写测试时,还可使用以下属性: // //使用 ClassInitialize 在运行类中的第一个测试前先运行代码 //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //使用 ClassCleanup 在运行完类中的所有测试后再运行代码 //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //使用 TestInitialize 在运行每个测试前先运行代码 //[TestInitialize()] //public void MyTestInitialize() //{ //} // //使用 TestCleanup 在运行完每个测试后运行代码 //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///IsEmpty 的测试 ///</summary> public void IsEmptyTestHelper <T>() { LinkQueue <T> target = new LinkQueue <T>(); // TODO: 初始化为适当的值 bool expected = true; // TODO: 初始化为适当的值 bool actual; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); target.In(default(T)); Assert.IsFalse(target.IsEmpty()); }
static void Main(string[] args) { IQueue<string> queue = new LinkQueue<string>(); queue.EnQueue("a1"); queue.EnQueue("a2"); queue.EnQueue("a3"); while (queue.IsEmpty() == false) { Console.WriteLine(queue.QueueFront); queue.DeQueue(); } }
/// <summary> /// �õ�AOV���������������� /// </summary> /// <returns>AOV����������������</returns> public string TopoSort() { string Result = string.Empty; int[] ID = GetInDegressList(); LinkQueue<int> LQ = new LinkQueue<int>(); for (int i = 0; i < vertexCount; i++) { if (ID[i] == 0) LQ.EnQueue(i); } if (LQ.Length == vertexCount) throw new Exception("������ͼ�������."); while (LQ.IsEmpty() == false) { int j = LQ.QueueFront; LQ.DeQueue(); Result += vertexList[j].VertexName + "\n"; EdgeNode p = vertexList[j].FirstNode; while (p != null) { ID[p.Index]--; if (ID[p.Index] == 0) { LQ.EnQueue(p.Index); } p = p.Next; } } int k; for (k = 0; k < vertexCount; k++) if (ID[k] != 0) break; return (k == vertexCount) ? Result : "��AOV���л�."; }
/// <summary> /// �õ���������������� /// </summary> /// <param name="startNodeName">���й��������������ʼ������</param> /// <returns>���������������</returns> public string BFSTraversal(string startNodeName) { string BFSResult = string.Empty; int i = GetIndex(startNodeName); if (i != -1) { for (int j = 0; j < vertexCount; j++) vertexList[j].Visited = false; vertexList[i].Visited = true; BFSResult += vertexList[i].VertexName + "\n"; LinkQueue<int> Q = new LinkQueue<int>(); Q.EnQueue(i); while (Q.IsEmpty() == false) { int j = Q.QueueFront; Q.DeQueue(); EdgeNode p = vertexList[j].FirstNode; while (p != null) { if (vertexList[p.Index].Visited == false) { vertexList[p.Index].Visited = true; BFSResult += vertexList[p.Index].VertexName + "\n"; Q.EnQueue(p.Index); } p = p.Next; } } } return BFSResult; }