// Directed graph implementation public class Graph { private int [][] adj; private String [] name; private int numVerticesPresent; private static final int MAX = 10; // Assume a maximum of 10 vertices. public Graph() { adj = new int [MAX][MAX]; name = new String[MAX]; numVerticesPresent = 0; } // copy constructor public Graph(Graph g) { adj = new int [MAX][MAX]; name = new String[MAX]; numVerticesPresent = g.numVerticesPresent; for (int i = 0; i < numVerticesPresent; ++i) { name[i] = g.name[i]; for (int j = 0; j < numVerticesPresent; ++j) adj[i][j] = g.adj[i][j]; } } public void addVertex(String s) { name[numVerticesPresent] = s; ++numVerticesPresent; } public void addEdge(String s1, String s2) { int i1 = findVertex(s1); int i2 = findVertex(s2); adj[i1][i2] = 1; } private int findVertex(String s) { for (int i = 0; i < numVerticesPresent; ++i) if (name[i].equals(s)) return i; return -1; } // Go down the column and count the 1's. public int inDegree(String s) { int vertexNum = findVertex(s); int retVal = 0; for (int i = 0; i < numVerticesPresent; ++i) if (adj[i][vertexNum] > 0) ++retVal; return retVal; } public int inDegree(int vertexNum) { int retVal = 0; for (int i = 0; i < numVerticesPresent; ++i) if (adj[i][vertexNum] > 0) ++retVal; return retVal; } // Remove vertex as well as its out edges. // ADD CODE HERE public void removeVertex(int vertexNum) { } // Determine an appopriate toplogical ordering. // ADD CODE HERE. public void topOrdering() { } }