日期:2014-05-17  浏览次数:21011 次

数据结构(C#)--图结构的实现输出以及图结构的深度和广度优先搜索和Dijkstra 算法的最小路径以及最小生成树的实现

// 实验小结 吴新强于2013年3月19日18:45:59 桂电 2507实验室
// 主要学习图结构的实现输出以及图结构的深度和广度优先搜索和Dijkstra 算法的最小路径以及最小生成树的实现
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Chapter16
{
    class Program
    {
        static void Main(string[] args)
        {
            // 简单的图输出
            Console.WriteLine("简单的图输出:");
            Graph the1Graph = new Graph(4);
            the1Graph.AddVertex("A");
            the1Graph.AddVertex("B");
            the1Graph.AddVertex("C");
            the1Graph.AddVertex("D");
            the1Graph.AddEdge(0, 1);
            the1Graph.AddEdge(1, 2);
            the1Graph.AddEdge(2, 3);
            the1Graph.TopSort();
            Console.WriteLine();
            Console.WriteLine("完成.");
            Console.WriteLine();


            Graph theGraph = new Graph(6);
            theGraph.AddVertex("CS1");
            theGraph.AddVertex("CS2");
            theGraph.AddVertex("DS");
            theGraph.AddVertex("OS");
            theGraph.AddVertex("ALG");
            theGraph.AddVertex("AL");
            theGraph.AddEdge(0, 1);
            theGraph.AddEdge(1, 2);
            theGraph.AddEdge(1, 5);
            theGraph.AddEdge(2, 3);
            theGraph.AddEdge(2, 4);
            theGraph.TopSort();
            Console.WriteLine();
            Console.WriteLine("完成.");
            // theGraph.ShowVertex(4);
            Console.WriteLine("输出没有后继结点顶点:" + theGraph.NoSuccessors());
            theGraph.DelVertex(1);
      &n