数据结构创建邻接矩阵:画出下图的邻接矩阵存储结构

数据结构 第7章 图_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
文档贡献者贡献于
评价文档:
81页免费28页免费52页免费23页免费21页免费 41页免费92页免费14页免费91页免费191页1下载券
喜欢此文档的还喜欢345页免费32页免费2页免费3页免费4页免费
数据结构 第7章 图|严​女​士​版​本​的​数​据​结​构​教​材​ ​第​七​章​ ​图
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
大小:1.31MB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢c#数据结构————图的邻接矩阵储存 - 把我的欢乐带给你 - 博客园
这一段时间偶一直在研究图的写法,这个比链表难多了,肯定有很多错误的地方,希望各位同道给与指点。在此谢过。
图的节点:
public class Node
private int//
private string//
internal NodesC//
private object
public Node()
nodes = new NodesCollection(this);
public string Data
data = value;
public int Num
num = value;
public virtual NodesCollection Nodes
return this.
     }
public object Parant
parant = value;
 在图中,是节点的集合,所以有了节点的集合类:
public class NodesCollection:CollectionBase
private object
public NodesCollection()
public NodesCollection(object parent)
this.self =
public Node this[int index]
return (Node) base.List[index];
public object Parent
return this.
this.self = value;
private void InitNodeCollection(Node node1)
node1.Parant = this.P
protected override void OnSet(int index, object oldValue, object newValue)
this.InitNodeCollection((Node) newValue);
base.OnSet(index, oldValue, newValue);
public void Add(Node item)
base.List.Add(item);
public void AddAt(int index, Node item)
base.List.Insert(index, item);
public bool Contains(Node item)
return base.List.Contains(item);
public int IndexOf(Node item)
return base.List.IndexOf(item);
public void Remove(Node item)
base.List.Remove(item);
    }
再说边了,
public class Edge
private N//
private N//
private int//
internal EdgesC//
private object
public Edge()
snode = new Node();
enode = new Node();
edges = new EdgesCollection(this);
public Node Snode
snode = value;
public Node Enode
enode = value;
public int Svalue
svalue = value;
public virtual EdgesCollection Edges
return this.
public object Parant
parant = value;
边的集合类:
public class EdgesCollection:CollectionBase
private object
public EdgesCollection()
public EdgesCollection(object parent)
this.self =
public Edge this[int index]
return (Edge) base.List[index];
public object Parent
return this.
this.self = value;
         }
private void InitNodeCollection(Edge node1)
node1.Parant = this.P
protected override void OnSet(int index, object oldValue, object newValue)
this.InitNodeCollection((Edge) newValue);
base.OnSet(index, oldValue, newValue);
public void Add(Edge item)
base.List.Add(item);
public void AddAt(int index, Edge item)
base.List.Insert(index, item);
public bool Contains(Edge item)
return base.List.Contains(item);
public int IndexOf(Edge item)
return base.List.IndexOf(item);
public void Remove(Edge item)
base.List.Remove(item);
    }
图的创建:
public class Graphic
private N//
private E//
public GraphK
public Graphic()
node = new Node();
edge = new Edge();
public enum GraphKind
public GraphKind Kind
return this.
this.kind = value;
public Node Node
return this.
this.node = value;
public Edge Edge
return this.
this.edge = value;
public void CreateGraph(int n,int e)//n为边数
int i,j,k,w;
object b,t;
Graphic Graphic1 = new Graphic();
Console.Write(&\n和边数e&);
for(i=0;i&n;i++)
Console.Write(&\t个顶点的信息:&);
Node node1 = new Node();
node1.Num =
node1.Data = i.ToString();
Graphic1.Node.Nodes.Add(node1);
for(i=0;i&n;i++)
for(j=0;j&n;j++)
Edge edge1 = new Edge();
edge1.Snode = Graphic1.Node.Nodes[i];
edge1.Enode = Graphic1.Node.Nodes[j];
edge1.Svalue = 0;
Graphic1.Edge.Edges.Add(edge1);
for(k=0;k&e;k++)
Console.Write(&条边=&\n\t起点:&);
b = Console.ReadLine();
              Console.Write(&
t = Console.ReadLine();
Console.Write(&
w = int.Parse(Console.ReadLine());
while(i&n && Graphic1.Node.Nodes[i].Data!=b.ToString())
Console.Write(&
Console.Error.Close();
while(j&n && Graphic1.Node.Nodes[j].Data!=t.ToString())
Console.Write(&
Console.Error.Close();
Graphic1.Edge.Edges[k].Svalue =w;
这是我写的图的邻接矩阵存储方式。大家多多指正错误哈。
我们都是新手希望大虾们不要笑我哈,只是想认真学习一种思想。
msdn上有关于c#数据结构的一个系列文章, 去参考一下吧
是网上的还是光盘上的???
是光盘上还是网站上。我安转了msdn,没有找到。
不过先自己写,在参考别人的,也不错哈。呵呵
我这里是教育网,我用代理搜索了,只有链表。还请idior指教带答案更新的数据结构复习题_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
21页免费40页免费26页免费14页免费8页免费 6页免费4页免费12页1下载券98页7下载券55页1下载券
喜欢此文档的还喜欢5页1下载券21页1下载券21页免费100页1下载券814页1下载券
带答案更新的数据结构复习题|数​据​结​构​习​题
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢复习题_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
92页免费91页免费71页免费79页免费155页2下载券 51页免费60页1下载券54页免费79页免费112页1下载券
喜欢此文档的还喜欢47页免费16页免费57页免费25页免费54页免费
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢

我要回帖

更多关于 数据结构邻接矩阵 的文章

 

随机推荐