数据结构之图 Part2 - 3
十字链表
简单的说就是邻接表和逆邻接表的合体,解决了原邻接表或者逆邻接表出度和入度的计算无法兼得的问题。
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的更多相关文章
- 数据结构之图 Part2 - 1
邻接矩阵 网上很少有C# 写图的数据结构的例子,实际的项目中也从来没用过Array 这坨东西,随手写个,勿喷. namespace LH.GraphConsole { public struct Gr ...
- 数据结构之图 Part2 - 2
邻接表 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...
- python数据结构之图的实现
python数据结构之图的实现,官方有一篇文章介绍,http://www.python.org/doc/essays/graphs.html 下面简要的介绍下: 比如有这么一张图: A -> B ...
- hdu 1233:还是畅通工程(数据结构,图,最小生成树,普里姆(Prim)算法)
还是畅通工程 Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- 利用python+graphviz绘制数据结构关系图和指定目录下头文件包含关系图
作为一名linux系统下的C语言开发,日常工作中经常遇到两个问题: 一是分析代码过程中,各种数据结构互相关联,只通过代码很难理清系统中所有结构体的整体架构,影响代码消化的效率; 二是多层头文件嵌套包含 ...
- python数据结构之图的实现方法
python数据结构之图的实现方法 本文实例讲述了python数据结构之图的实现方法.分享给大家供大家参考.具体如下: 下面简要的介绍下: 比如有这么一张图: A -> B A ...
- python数据结构之图深度优先和广度优先实例详解
本文实例讲述了python数据结构之图深度优先和广度优先用法.分享给大家供大家参考.具体如下: 首先有一个概念:回溯 回溯法(探索与回溯法)是一种选优搜索法,按选优条件向前搜索,以达到目标.但当探索到 ...
- 数据结构之图 Part1
Part 1 预计使用7天的时间来过掉图相关的数据结构.第一天主要是一天图的基本概念,熟练掌握定义是一切交流和沟通的基础. 1定义 1.1图 有穷非空顶点,外加边. G(V,E) Graph Vert ...
- C++数据结构之图
图的实现是一件很麻烦的事情,很多同学可能在学数据结构时只是理解了图的基本操作和遍历原理,但并没有动手实践过.在此,我说说我的实现过程. 首先,在草稿纸上画一个图表,这里是有向图,无向图也一样,如下: ...
随机推荐
- 浏览器js自动查表脚本
javascript: void((function() {$.get("", {wen: "880350384879600241",action: " ...
- tornado RequestHandler request.body & request.arguments
request.body , 请求的原始内容,post方式放在body中的. request.arguments, body参数和url参数的统一体, 同时也是经过“加工”,解码的. eg.在对接其他 ...
- 【GoLang】GoLang 单元测试、性能测试使用方法
单元测试代码: ackage test import ( // "fmt" "testing" ) func Test_FlowControl(t *testi ...
- Binary Tree Longest Consecutive Sequence
Given a binary tree, find the length of the longest consecutive sequence path (连续的路径,不是从小到大). The pa ...
- POJ 3009
http://poj.org/problem?id=3009 一个搜索的题目: 大意就是一个冰球,在冰面上滑动,你打击一次,就沿一个反向滑动,知道碰到墙就会停下,而墙则会破碎. 求从起点到终点的最短的 ...
- ABAP 内表的行列转换-NEW
REPORT Z_TEST_COL_TO_ROW. TYPE-POOLS: slis. TABLES: mseg,mkpf. DATA: gd_fieldcat TYPE slis_t_fieldca ...
- codeforces 425C Sereja and Two Sequences(DP)
题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...
- 【linux】sudo su切换到root权限
在用户有sudo权限但不知道root密码时可用 sudo su切换到root用户
- LeetCode 171 Excel Sheet Column Number
Problem: Given a column title as appear in an Excel sheet, return its corresponding column number. F ...
- NEFU 503 矩阵求解 (非01异或的高斯消元)
题目链接 中文题,高斯消元模板题. #include <iostream> #include <cstdio> #include <cmath> #include ...