兴奋的倔黄牛 2021-08-06 15:43 采纳率: 0%
浏览 27
已结题

c#邻接表,temp一直是null

using System;

namespace ConsoleApp1
{
class Program
{
public class BanLie
{
public string[] name;
public int bnum;
public int[] maxqual;
public string[] start;
public class ALgraph
{
public class EdgeNode
{
public int adjvex;
public int weight;
public int length;
public int time;
public string[] type;
public float[] price;
public EdgeNode next;
public EdgeNode(int adjvex)
{
this.adjvex = adjvex;
}
}
public class VertexNode
{
public string vertex;
public EdgeNode first;
public VertexNode(string vertex)
{
this.vertex = vertex;
this.first = null;
}
}
public class GraphAdjlist
{
public VertexNode[] vertexNode;
public int vexnum, arcnum;
public GraphAdjlist(int vexnum, int arcnum,string vertexs)
{
this.vexnum = vexnum;
this.arcnum = arcnum;
string[] vertex = vertexs.Split(',');
vertexNode = new VertexNode[vexnum];
for (int i = 0; i < vexnum; i++)
{
vertexNode[i] = new VertexNode(vertex[i]);
}

                }
            }
            public GraphAdjlist graphAdjlist = new GraphAdjlist(4, 5,"a,b,c,d") { };
            public void InitEdges(int fromVertexNode, int toVertexNode)
            {
                EdgeNode temp = new EdgeNode(fromVertexNode) { next = graphAdjlist.vertexNode[toVertexNode].first };
                graphAdjlist.vertexNode[toVertexNode].first = temp;
                temp = new EdgeNode(toVertexNode) { next = graphAdjlist.vertexNode[fromVertexNode].first };
                graphAdjlist.vertexNode[fromVertexNode].first = temp;
            }
            public void CreatALgraph()
            {
                InitEdges(0, 1);
                InitEdges(0, 2);
                InitEdges(0, 3);
                InitEdges(2, 1);
                InitEdges(2, 3);
            }
            public void ShowALgraph()
            {
                for (int i = 0; i < graphAdjlist.vexnum; i++)
                {
                    Console.WriteLine("顶点" + i + "为:" + graphAdjlist.vertexNode[i].vertex + "--first--");
                    EdgeNode temp = new EdgeNode(0);
                    temp = graphAdjlist.vertexNode[i].first;
                    Console.WriteLine(temp.adjvex + "--next--");
                    while (temp != null)
                    {
                        Console.WriteLine(temp.adjvex + "--next--");
                        temp = temp.next;
                    }
                    Console.WriteLine("END-" + graphAdjlist.vertexNode[i].vertex);
                }

            }
        }
    }
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        BanLie.ALgraph CreatALgraph = new BanLie.ALgraph();
        CreatALgraph.CreatALgraph();
        BanLie.ALgraph ShowALgraph = new BanLie.ALgraph();
        ShowALgraph.ShowALgraph();
    }
    public class com
    {
        public string[] cname;
        public float[] cqual;
        public string[] ctype;
        public string[] formcountry;
        public string[] tocountry;
        public float[] price;
    }
}

}

  • 写回答

1条回答 默认 最新

  • 有问必答小助手 2021-08-09 17:04
    关注

    你好,我是有问必答小助手。为了技术专家团更好地为您解答问题,烦请您补充下(1)问题背景详情,(2)您想解决的具体问题,(3)问题相关代码图片或者报错信息。便于技术专家团更好地理解问题,并给出解决方案。

    您可以点击问题下方的【编辑】,进行补充修改问题。
    img

    评论

报告相同问题?

问题事件

  • 系统已结题 8月14日
  • 创建了问题 8月6日

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配