zoukankan      html  css  js  c++  java
  • DIj

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace DefineGraph
    {
    class Graph
    {
    private const int Number = 10; //图中所能包含的点上限
    private Vertex[] vertiexes; //顶点数组
    public int[,] adjmatrix; //邻接矩阵
    int numVerts = 0; //统计当前图中有几个点
    public Graph() //初始化图
    {

    adjmatrix = new Int32[Number, Number]; //初始化邻接矩阵和
    vertiexes = new Vertex[Number];//初始化顶点数组
    for (int i = 0; i < Number; i++)//将代表邻接矩阵的表全初始化为0
    {
    for (int j = 0; j < Number; j++)
    {
    adjmatrix[i, j] = 0;
    }
    }
    }
    public void AddVertex(String v)//向图中添加节点
    {
    vertiexes[numVerts] = new Vertex(v);
    numVerts++;
    }
    public void AddEdge(int vertex1, int vertex2,int weight) //向图中添加有向边
    {
    adjmatrix[vertex1, vertex2] = weight;
    //adjmatrix[vertex2, vertex1] = 1;
    }
    public void DisplayVert(int vertexPosition) //显示点
    {
    Console.WriteLine(vertiexes[vertexPosition].ID + " ");
    }

    public void Dijkstr(Vertex s)
    {
    List<Vertex> listAbsPoi = new List<Vertex>();
    List<Vertex> listUnAbsPoi = new List<Vertex>();
    listAbsPoi.Add(s);
    while (true)
    {
    listUnAbsPoi = GetAdjPoint(s);
    for (int i = 0; i < listUnAbsPoi.Count; i++)
    {
    if (listUnAbsPoi.Count == 0)
    break;
    }
    for (int i = 0; i < length; i++)
    {

    }
    }

    }
    public List<Vertex> GetAdjPoint(Vertex v)
    {
    List<Vertex> ListAdjPoint = new List<Vertex>();
    for (int i = 0; i <adjmatrix.Length; i++)
    {
    if (adjmatrix[Convert.ToInt32(v.ID.Substring(1, 1)), i] != 0)
    {
    ListAdjPoint.Add(vertiexes[i]);
    }
    }
    return ListAdjPoint;
    }

    }
    class Vertex
    {
    public string ID;
    public bool IsVisited;
    public Vertex(string Vertexdata)
    {
    ID = Vertexdata;
    }
    }

    }

  • 相关阅读:
    Software Update Services 2.0 概述
    Windows 2000组策略
    Windows 2000 默认安全策略设置
    C语言I博客作业06
    C语言I博客作业08
    C语言I博客作业09
    C语言I博客作业03
    C语言12019级秋季作业第一周作业
    C语言I博客作业02
    C语言I博客作业05
  • 原文地址:https://www.cnblogs.com/1521681359qqcom/p/11208675.html
Copyright © 2011-2022 走看看