This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CMPT 225 D1 - Fall 2010 - Assignment 2 (7%) Submit your solutions online by 5:00 pm, Thursday, Oct. 21, 2010. 1. [40 marks] Implement a C++ Graph Class Implement a C++ class iGraph with the following public functions: iGraph(int m) Constructor. It creates a new iGraph instance which represents a graph with no vertices and no edges, and has the capacity for up to m vertices. The assumption is that all vertices in the graph will be int values in the range 1 ...m . int max vertex() Returns the maximum int that can be used as a vertex (which is also the maximum number of vertices). bool has vertex( int v) Returns true iff v is a vertex of the graph. void add vertex( int v) Adds v to the set of vertices of the graph. void add edge( int u, int v) Adds ( u,v ) to the set of edges of the graph. bool has edge( int u, int v) Returns true iff ( u,v ) is an edge of the graph. void mark vertex( int v) Marks vertex v . void unmark all vertices() Unmarks all vertices. bool is marked(int v) Returns true iff vertex v is marked. int number of vertices() Returns the number of vertices of the graph. int number of edges() Returns the number of edges of the graph. bfs(int v) Executes a breadth-first search starting at vertex v , marking all vertices visited. It does not un-mark any vertex, and does not mark any vertex not visited. ~ iGraph() Destructor. You may implement it any way you like, consistent with the following: (a) You may not make any changes to these prototypes for the public methods; (b) You must implement it yourself, from scratch. That is, you may not implement it by embedding some existing graph class, you must use your own queue implementation, you must code your own data structure for storing edges, and you may not use vectors or other container-like library classes....
View Full Document
- Spring '12