Figure 2-2 of Data Structure

Source: Internet
Author: User

Adjacent table

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace LH.GraphConsole{    public struct AdjacencyListGraph    {        public List<EdgeItem>[] VertexNodes;        public AdjacencyListGraph(int vertexNumber)        {            VertexNodes = new List<EdgeItem>[vertexNumber];            for (int i = 0; i < vertexNumber; i++)            {                VertexNodes[i] = new List<EdgeItem>();            }        }    }    public struct EdgeItem    {        public int Weight;        public List<EdgeItem> NextNode;        public EdgeItem(int weight, List<EdgeItem> nextNote)        {            Weight = weight;            NextNode = nextNote;        }    }}

It is also a simple main program:

namespace LH.GraphConsole{    class Program    {        static void Main(string[] args)        {            AdjacencyList();        }        private static void AdjacencyList()        {            int vertexNumber = 5;            var adjacencyListGraph = new AdjacencyListGraph(vertexNumber);            adjacencyListGraph.VertexNodes[0].Add(new EdgeItem(6, adjacencyListGraph.VertexNodes[4]));            adjacencyListGraph.VertexNodes[1].Add(new EdgeItem(9, adjacencyListGraph.VertexNodes[0]));            adjacencyListGraph.VertexNodes[1].Add(new EdgeItem(3, adjacencyListGraph.VertexNodes[2]));            adjacencyListGraph.VertexNodes[2].Add(new EdgeItem(2, adjacencyListGraph.VertexNodes[0]));            adjacencyListGraph.VertexNodes[2].Add(new EdgeItem(5, adjacencyListGraph.VertexNodes[3]));            adjacencyListGraph.VertexNodes[3].Add(new EdgeItem(1, adjacencyListGraph.VertexNodes[4]));        }    }}

For the next part of Part3, see the cross linked list.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.