图的节点:
using System;
namespace structure
{
public class Node
{
private int num;//编号
private string data;//数据
internal NodesCollection nodes;//节点的集合
private object parant;
public Node()
{
nodes = new NodesCollection(this);
}
public string Data
{
get
{
return data;
}
set
{
data = value;
}
}
public int Num
{
get
{
return num;
}
set
{
num = value;
}
}
public virtual NodesCollection Nodes
{
get
{
return this.nodes;
}
}
public object Parant
{
get
{
return parant;
}
set
{
parant = value;
}
}
}
}
在图中,是节点的集合,所以有了节点的集合类:
using System;
using System.Collections;
namespace structure
{
public class NodesCollection:CollectionBase
{
private object self;
public NodesCollection()
{
}
public NodesCollection(object parent)
{
this.self = parent;
}
public Node this[int index]
{
get
{
return (Node) base.List[index];
}
}
public object Parent
{
get
{
return this.self;
}
set
{
this.self = value;
}
}
private void InitNodeCollection(Node node1)
{
node1.Parant = this.Parent;
}
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);
}
}
}
再说边了,
using System;
namespace structure
{
public class Edge
{
private Node snode;//起点
private Node enode;//终点
private int svalue;//权值
internal EdgesCollection edges;//边的集合
private object parant;
public Edge()
{
snode = new Node();
enode = new Node();
edges = new EdgesCollection(this);
}
public Node Snode
{
get
{
return snode;
}
set
{
snode = value;
}
}
public Node Enode
{
get
{
return enode;
}
set
{
enode = value;
}
}
public int Svalue
{
get
{
return svalue;
}
set
{
svalue = value;
}
}
public virtual EdgesCollection Edges
{
get
{
return this.edges;
}
}
public object Parant
{
get
{