图(Graph)-边缘

1,抽象数据类型:

public abstract class Graph {
	public abstract int vertices();
	public abstract int edges();
	public abstract boolean existsEdge(int i, int j);
	public abstract void putEdge(Object theEdge);
	public abstract void removeEdge(int i, int j);
	public abstract int degree(int i);
	public abstract int inDegree(int i);
	public abstract int outDegree(int i);
	public abstract Iterator iterator(int i);
}

2,节点定义:

public class Edge {
	int vertex1; // one end point of the edge
	int vertex2; // other end point of the edge

	public Edge(int theVertex1, int theVertex2) {
		vertex1 = theVertex1;
		vertex2 = theVertex2;
	}

	public String toString() {
		return "(" + String.valueOf(vertex1) + "," + String.valueOf(vertex2)
				+ ")";
	}
}

 

public class WeightedEdgeNode extends EdgeNode {
	Object weight;

	public WeightedEdgeNode(int theVertex, Object theWeight) {
		super(theVertex);
		weight = theWeight;
	}

	public String toString() {
		return String.valueOf(vertex) + " " + weight.toString();
	}
} 

3,继承关系图

你可能感兴趣的:(J#)