
CS 259
Homework 5:
Assigned on Monday, October 18, 1999
Due on Friday, October 29, 1999
1. Use your header file from Homework 3 to create an
implementation for the class LDG. Recall that each LDG
object will be a “labeled directed graph.” A labeled
directed graph is a set of vertices (also called nodes) and
directed edges. For each pair of vertices (a,b), there may
be an edge going from a to b and also there may be an
edge going from b to a. Each vertex will have a label -- a
(unique) integer value that is associated with it. LDG will
have the following functions:
A) constructor LDG (also create a copy constructor)
B) destructor ~LDG
C) add_vertex: Adds a new vertex with label of type integer.
D) connect: places edge from one vertex to another
E) remove_edge: removes an edge
F) isomorphic: You don’t have to implement this.
G)print_DLG: outputs a list of graph edges to cout.
H) num_vertices: returns the number of vertices in the graph
2. Create .h and .cpp files for a derived class of LDG called
LDAG, “labeled directed acyclic graph.” A graph is
acyclic if, for each vertex, there is no sequence of
directed edges leading back to that vertex. This derived
class should have one additional function:
A) total_order: this function returns a linked-list of the
labels of the vertices of the graph. We say that “label a > label
b” if label b occurs after label a does in the linked list. The linked
list should have the property that, for all a and b, if there is a way
to reach b from a using directed edges, then label a > label b.
Use the depth-first search algorithm described in class.