资源简介
C# 图 拓扑排序

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Graph
{
public class Graph
{
int numVertex;
int maxVertex;
Vertex[] vertexs;
int[] adjMatrix;
public Graph(int maxvertex1)
{
this.maxVertex = maxvertex1;
vertexs=new Vertex[maxVertex];
adjMatrix=new int[maxVertexmaxVertex];
numVertex = 0;
for (int i = 0; i < maxVertex; i++)
{
for (int j = 0; j < maxVertex; j++)
{
adjMatrix[i j] = 0;
}
}
}
public void AddVertex(string label1)
{
vertexs[numVertex++] = new Vertex(label1);
}
public void AddEdge(int start int end)
{
adjMatrix[start end] = 1;
}
public void ShowVertex(int v)
{
Console.Write( vertexs[v].label + “ “);
}
public int NoSuccessors()
{
bool isEdge ;
for (int i = 0; i < maxVertex; i++)
{
isEdge = false;
for (int j = 0; j < maxVertex; j++)
{
if (adjMatrix[i j] > 0)
{
isEdge = true;
break;
}
}
if (!isEdge)
{
return i;
}
}
return -1;
}
public void Delete(int index)
{
if (index != maxVertex - 1)
{
for (int i = index; i < maxVertex - 1; i++)
{
vertexs[i] = vertexs[i + 1];
}
for (int i = index; i < maxVertex; i++)
{
RemoveRow(index);
}
for (int i = 0; i < maxVertex - 1; i++)
{
RemoveCol(index);
}
}
maxVertex--;
}
private void RemoveCol(int index)
{
for (int i = 0; i < maxVertex; i++)
{
adjMatrix[iindex]=adjMatrix[iindex+1];
}
}
private void RemoveRow(int index)
{
for (int i = 0; i < maxVertex; i++)
{
adjMatrix[indexi]=adjMatrix[index+1i];
}
}
public void TopVertList()
{
Stack stack = new Stack();
while (maxVertex > 0)
{
int index=NoSuccessors();
if (index == -1)
{
Console.WriteLine(“节点包含环“);
return;
}
stack.Push(vertexs[index].label);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
I.A.... 6656 2012-11-27 19:21 Graph\Graph\bin\Debug\Graph.exe
I.A.... 19968 2012-11-27 19:21 Graph\Graph\bin\Debug\Graph.pdb
I.A.... 11600 2012-11-27 19:22 Graph\Graph\bin\Debug\Graph.vshost.exe
I.A.... 490 2010-03-17 22:39 Graph\Graph\bin\Debug\Graph.vshost.exe.manifest
I.A.... 3256 2012-11-27 19:21 Graph\Graph\Graph.cs
I.A.... 2550 2012-11-27 19:21 Graph\Graph\Graph.csproj
I.A.... 5814 2012-11-27 19:21 Graph\Graph\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
I.A.... 408 2012-11-27 19:22 Graph\Graph\obj\x86\Debug\Graph.csproj.FileListAbsolute.txt
I.A.... 6656 2012-11-27 19:21 Graph\Graph\obj\x86\Debug\Graph.exe
I.A.... 19968 2012-11-27 19:21 Graph\Graph\obj\x86\Debug\Graph.pdb
I.A.... 744 2012-11-27 19:21 Graph\Graph\Program.cs
I.A.... 1360 2012-11-27 10:51 Graph\Graph\Properties\AssemblyInfo.cs
I.A.... 176 2012-11-27 19:21 Graph\Graph\TopologicalSort.cs
I.A.... 348 2012-11-27 13:25 Graph\Graph\Vertex.cs
I.A.... 857 2012-11-27 10:51 Graph\Graph.sln
I.A..H. 16896 2012-11-27 19:43 Graph\Graph.suo
I..D... 0 2012-11-27 10:51 Graph\Graph\obj\x86\Debug\TempPE
I..D... 0 2012-11-27 19:21 Graph\Graph\obj\x86\Debug
I..D... 0 2012-11-27 19:21 Graph\Graph\bin\Debug
I..D... 0 2012-11-27 10:51 Graph\Graph\obj\x86
I..D... 0 2012-11-27 10:51 Graph\Graph\bin
I..D... 0 2012-11-27 10:51 Graph\Graph\obj
I..D... 0 2012-11-27 10:51 Graph\Graph\Properties
I..D... 0 2012-11-27 18:19 Graph\Graph
I..D... 0 2012-11-27 10:51 Graph
----------- --------- ---------- ----- ----
97747 25
- 上一篇:C#与TwinCAT通讯
- 下一篇:模拟退火算法C#源码+
相关资源
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
评论
共有 条评论