资源简介
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#源码+
- C#与TwinCAT通讯
- 将Halcon DeepLearning Tool工具生成的hdic
- K-means聚类C#实现
- c#与文字语音转换与语音播放
- 利用C#远程存取Access数据库
- C#设计的简单的用户登录界面窗体
- C#利用AT指令控制短信猫发送短信
- 会员积分管理系统C#版
- mtp文件传输for C#
- C#操作手持机识别RFID电子标签
- c#读取DLT645-2007电力协议,项目源码
- csWPF井字棋游戏
- 基于asp.net的BBS论坛
- C#使用IBatisNet操作Oracle10g数据库
- 测绘工程中的前方交会 c#
- 运动会成绩管理系统课程设计 C#
- c#wpf chart绘图 源代码 示波器
- C#WPF 绘制几何图形 2D坐标 sin曲线
- Devexpress GridControl冻结头部几行
- .NET C#研发的授权工具winform
- Winform C#Socket异步通信
- 在winform下,利用控件ZedGraph控件绘制
- FileUpload控件上传文件客户端验证格式
- C#波形图含源代码
- WPF 关于C#代码实现ControlTemplate
- c#获取窗体句柄模拟鼠标点击
- C#+Sql server超市管理系统
- C#串口助手源码新手
- C# Ftp客户端源码
评论
共有 条评论