十字链表

简单的说就是邻接表和逆邻接表的合体,解决了原邻接表或者逆邻接表出度和入度的计算无法兼得的问题。

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

namespace LH.GraphConsole
{
    public struct OrthogonalListGraph
    {
        public NodeItem[] VertexNodes;

        public OrthogonalListGraph(int size)
        {
            VertexNodes = new NodeItem[size];
        }
    }

    public struct NodeItem
    {
        public List<OrthEdgeItem> InList;
        public List<OrthEdgeItem> OutList;

        public NodeItem(List<OrthEdgeItem> inList, List<OrthEdgeItem> outList)
        {
            InList = inList;
            OutList = outList;
        }
    }

    public class OrthEdgeItem
    {
        public int Weight;
        public string Name;

        public OrthEdgeItem(int weight, string name)
        {
            Weight = weight;
            Name = name;
        }
    }
}

简单的主函数:

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

namespace LH.GraphConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            OrthogonalList();
        }

        private static void OrthogonalList()
        {
            var size = 5;
            var orgthListGraph = new OrthogonalListGraph(size);

            var orgEdge03 = new OrthEdgeItem(1, "edge03");
            var orgEdge10 = new OrthEdgeItem(1, "edge10");
            var orgEdge12 = new OrthEdgeItem(1, "edge12");
            var orgEdge21 = new OrthEdgeItem(1, "edge21");
            var orgEdge20 = new OrthEdgeItem(1, "edge20");

            var inList0 = new List<OrthEdgeItem>();
            inList0.Add(orgEdge10);
            inList0.Add(orgEdge20);

            var outList0 = new List<OrthEdgeItem>();
            outList0.Add(orgEdge03);

            var nodeItem0 = new NodeItem(inList0, outList0);
            var nodeItem1 = new NodeItem();
            var nodeItem2 = new NodeItem();
            var nodeItem3 = new NodeItem();
            var nodeItem4 = new NodeItem();

            orgthListGraph.VertexNodes[0] = nodeItem0;
            orgthListGraph.VertexNodes[1] = nodeItem1;
            orgthListGraph.VertexNodes[2] = nodeItem2;
            orgthListGraph.VertexNodes[3] = nodeItem3;
            orgthListGraph.VertexNodes[4] = nodeItem4;
        }
    }
}

简要说明,只是为了便于理解数据结构,没有刻意的去标准实现,见谅。

数据结构之图 Part2 - 3的更多相关文章

  1. 数据结构之图 Part2 - 1

    邻接矩阵 网上很少有C# 写图的数据结构的例子,实际的项目中也从来没用过Array 这坨东西,随手写个,勿喷. namespace LH.GraphConsole { public struct Gr ...

  2. 数据结构之图 Part2 - 2

    邻接表 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...

  3. python数据结构之图的实现

    python数据结构之图的实现,官方有一篇文章介绍,http://www.python.org/doc/essays/graphs.html 下面简要的介绍下: 比如有这么一张图: A -> B ...

  4. hdu 1233:还是畅通工程(数据结构,图,最小生成树,普里姆(Prim)算法)

    还是畅通工程 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  5. 利用python+graphviz绘制数据结构关系图和指定目录下头文件包含关系图

    作为一名linux系统下的C语言开发,日常工作中经常遇到两个问题: 一是分析代码过程中,各种数据结构互相关联,只通过代码很难理清系统中所有结构体的整体架构,影响代码消化的效率; 二是多层头文件嵌套包含 ...

  6. python数据结构之图的实现方法

    python数据结构之图的实现方法 本文实例讲述了python数据结构之图的实现方法.分享给大家供大家参考.具体如下: 下面简要的介绍下: 比如有这么一张图:     A -> B     A ...

  7. python数据结构之图深度优先和广度优先实例详解

    本文实例讲述了python数据结构之图深度优先和广度优先用法.分享给大家供大家参考.具体如下: 首先有一个概念:回溯 回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标.但当探索到 ...

  8. 数据结构之图 Part1

    Part 1 预计使用7天的时间来过掉图相关的数据结构.第一天主要是一天图的基本概念,熟练掌握定义是一切交流和沟通的基础. 1定义 1.1图 有穷非空顶点,外加边. G(V,E) Graph Vert ...

  9. C++数据结构之图

    图的实现是一件很麻烦的事情,很多同学可能在学数据结构时只是理解了图的基本操作和遍历原理,但并没有动手实践过.在此,我说说我的实现过程. 首先,在草稿纸上画一个图表,这里是有向图,无向图也一样,如下: ...

随机推荐

  1. struts2回显指定的错误信息

     <s:fielderror />  显示全部的 错误消息(用addFieldError方法添加的 )   <s:fielderror>            <s:pa ...

  2. centos 本地dns配置

    折腾了差不多两天,看了不少中文,英文文档.终于搞定,记录下心得.本文只讨论正向解析. 安装 ============= yum install bind 全局配置 ========= 由于只是做本地d ...

  3. python gui之tkinter界面设计pythonic设计

    ui的设计,控件id的记录是一件比较繁琐的事情. 此外,赋值和读取数据也比较繁琐,非常不pythonic. 有没有神马办法优雅一点呢?life is short. 鉴于控件有name属性,通过dir( ...

  4. Centos安装firefox/chrome

    centos安装chrome:去官网下载chrome安装包(xxx.rpm),带软件安装工具的系统双击该xxx.rpm就能自动安装,或者sudo rpm -i xxx.rpm安装. centos卸载自 ...

  5. 【Networking】flannel,pipework,weave,udp,vxlan,ovs等资料

    Add Open vSwitch-based multitenant backend for use with OpenShift / Kubernetes:  https://github.com/ ...

  6. 【GoLang】GoLang 的流程与函数

    003.GO流程与函数 1 概述 1.1 Go中流程控制分三大类:条件判断,循环控制和无条件跳转 2 流程 2.1 if 2.1.1 if条件判断语句中不需要括号 2.1.2 条件判断语句里面允许声明 ...

  7. Git – Fast Forward 和 no fast foward

    Git 很是强大,在体验过rebase的华丽之后,再次发现之前在TFS上遇到的问题一下都有解了.但也印证了Git深入并非易事.这篇就谈下一个容易迷糊的概念:Fast forward. Fast-For ...

  8. poj 1326

    http://poj.org/problem?id=1326 一个模拟的水题 题意就是要你算飞行的英里数. F代表头等舱,为实际飞行的英里数的2倍. B为商务舱,为实际飞行的英里数的1.5倍. Y为经 ...

  9. Java for LeetCode 210 Course Schedule II

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  10. python2.79安装

    从官网下载最新的安装程序,基于windows的,也可以直接百度下载 点击安装,如果其他用户不需要python的话,可以使用第二个,不过我们一般都是单用户,所以没差 选择安装路径,可按默认路径安装,也可 ...