GraphListTester - System.out.println(); } } public static...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
r public class GraphListTester { private static int gcd(int a,int b) { if (a==0) return b; if (b==0) return a; return gcd(b,a%b); } private static boolean coprime(int a,int b) { return gcd(a,b)==1; } public static void print(GraphList G) { System.out.println("List of edges:"); for (int u=0; u<G.getNumVertices(); u++) { // traverse through neigbors of u int v; for (int k=1; (v=G.kth_Adjacent(u,k)) >=0; k++) if (u<v) // print each edge only once System.out.print(" ["+u+","+v+"]");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.println(); } } public static void main(String args) { GraphList G = new GraphList(10); // graph with 10 vertices // add some edges for (int u=0; u<G.getNumVertices(); u++) for (int v=u+1; v<G.getNumVertices(); v++) if (coprime(u,v)) G.addEdge(u,v); print(G); // remove some edges for (int u=1; u<G.getNumVertices(); u++) G.removeEdge(u-1,u); print(G); } }...
View Full Document

This note was uploaded on 04/26/2010 for the course CMPT 225 taught by Professor Annelavergne during the Spring '07 term at Simon Fraser.

Ask a homework question - tutors are online