资源简介
Java语言程序设计第10版(基础篇)课后习题的答案源码,注意就是每章最后的那部分题不包括课间习题答案。课间习题答案我也有上传,进入我的资源页查看。
代码片段和文件信息
import java.util.*;
public abstract class AbstractGraph implements Graph {
protected List vertices = new ArrayList<>(); // Store vertices
protected List> neighbors
= new ArrayList<>(); // Adjacency lists
/** Construct an empty graph */
protected AbstractGraph() {
}
/** Construct a graph from vertices and edges stored in arrays */
protected AbstractGraph(V[] vertices int[][] edges) {
for (int i = 0; i < vertices.length; i++)
addVertex(vertices[i]);
createAdjacencyLists(edges vertices.length);
}
/** Construct a graph from vertices and edges stored in List */
protected AbstractGraph(List vertices List edges) {
for (int i = 0; i < vertices.size(); i++)
addVertex(vertices.get(i));
createAdjacencyLists(edges vertices.size());
}
/** Construct a graph for integer vertices 0 1 2 and edge list */
protected AbstractGraph(List edges int numberOfVertices) {
for (int i = 0; i < numberOfVertices; i++)
addVertex((V)(new Integer(i))); // vertices is {0 1 ...}
createAdjacencyLists(edges numberOfVertices);
}
/** Construct a graph from integer vertices 0 1 and edge array */
protected AbstractGraph(int[][] edges int numberOfVertices) {
for (int i = 0; i < numberOfVertices; i++)
addVertex((V)(new Integer(i))); // vertices is {0 1 ...}
createAdjacencyLists(edges numberOfVertices);
}
/** Create adjacency lists for each vertex */
private void createAdjacencyLists(
int[][] edges int numberOfVertices) {
for (int i = 0; i < edges.length; i++) {
addEdge(edges[i][0] edges[i][1]);
}
}
/** Create adjacency lists for each vertex */
private void createAdjacencyLists(
List edges int numberOfVertices) {
for (Edge edge: edges) {
addEdge(edge.u edge.v);
}
}
@Override /** Return the number of vertices in the graph */
public int getSize() {
return vertices.size();
}
@Override /** Return the vertices in the graph */
public List getVertices() {
return vertices;
}
@Override /** Return the object for the specified vertex */
public V getVertex(int index) {
return vertices.get(index);
}
@Override /** Return the index for the specified vertex object */
public int getIndex(V v) {
return vertices.indexOf(v);
}
@Override /** Return the neighbors of the specified vertex */
public List getNeighbors(int index) {
List result = new ArrayList<>();
for (Edge e: neighbors.get(index))
result.add(e.v);
return result;
}
@Override /** Return the degree for a specified vertex */
public int getDegree(int v) {
return neighbors.get(v).size();
}
@Override /** Print the edges */
public void printEdges() {
for (int u = 0; u < neighbors.size(); u++) {
System.out.
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8759 2013-05-26 13:33 exercise\AbstractGraph.java
文件 601 2012-03-05 15:13 exercise\AbstractTree.java
文件 7726 2011-12-14 13:44 exercise\AVLTree.java
文件 1758 2013-06-17 13:41 exercise\BarChart.java
文件 1222 2011-07-26 20:31 exercise\BMI.java
文件 7859 2011-12-12 23:55 exercise\BST.java
文件 1633 2013-06-17 13:33 exercise\ChartModel.java
文件 1075 2011-10-11 22:01 exercise\CheckPrimeNumbers.java
文件 1240 2011-10-11 22:01 exercise\Circle.java
文件 4006 2013-04-27 09:33 exercise\ClockPane.java
文件 1975 2013-04-21 11:35 exercise\ComputeTax.java
文件 1685 2011-10-11 22:01 exercise\Cylinder.java
文件 1892 2011-10-11 22:01 exercise\DecryptUsingRSAKey.java
文件 1556 2011-10-11 22:01 exercise\DecryptUsingSymmetricKey.java
文件 1620 2013-03-31 13:50 exercise\Desc
文件 1750 2011-10-11 22:01 exercise\Deviation.java
文件 807 2011-10-11 22:01 exercise\DirectorySize.java
文件 209 2011-10-11 22:01 exercise\Displayable.java
文件 2430 2011-10-11 22:01 exercise\EncryptUsingRSAKey.java
文件 1556 2011-10-11 22:01 exercise\EncryptUsingSymmetricKey.java
文件 3966 2011-12-05 20:56 exercise\Evaluateex
文件 229 2011-10-11 22:01 exercise\Exercise01_01.java
文件 131 2013-08-25 14:40 exercise\Exercise01_01Extra.java
文件 302 2011-10-11 22:01 exercise\Exercise01_02.java
文件 132 2013-08-25 14:40 exercise\Exercise01_02Extra.java
文件 335 2011-10-11 22:01 exercise\Exercise01_03.java
文件 311 2011-10-11 22:01 exercise\Exercise01_04.java
文件 145 2011-10-11 22:01 exercise\Exercise01_05.java
文件 142 2011-10-11 22:01 exercise\Exercise01_06.java
文件 187 2011-10-11 22:01 exercise\Exercise01_07.java
............此处省略1156个文件信息
评论
共有 条评论