// Port of mjd@cs.auckland.ac.nz CS220 Java graph library into C# .Net // by r.nicolescu@auckland.ac.nz (Aug'06) using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; /* * Graph implementation using adjacency lists (from CS220 library) */ public class Graph { // --------------------------------------------------------------- // Internal Representation and Constructors // --------------------------------------------------------------- private List< List > _adj; // Vector of Vector of integers. private void _allocate(int n) { _adj = new List>(); for (int i=0; i()); } public Graph() { // default constructor _allocate(0); } public Graph(Graph G) { // copy constructor int n = G.order(); _adj = new List>(); for (int i=0; i 0) { for (int i=0; i()); } } public void removeVertex(int i) { _adj.RemoveAt(i); for (int u=0; u uu = _adj[u]; uu.Remove(i); // remove i from adj lists for (int v=0; v i) uu[v] = nbr - 1; } } } public void addArc(int i, int j) { if (isArc(i, j)) return; _adj[i].Add(j); } public void removeArc(int i, int j) { _adj[i].Remove(j); } // --------------------------------------------------------------- // Accessor Methods // --------------------------------------------------------------- public bool isArc(int i, int j) { return _adj[i].Contains(j); } public int inDegree(int i) { int sz = 0; for (int j= 0; j neighbors(int i) { return new List(_adj[i]); } public int order() { return _adj.Count; } public int size() { // Number of arcs (counts edges twice). int sz = 0; for (int i=0; i