Question: Class Specification UML Class Diagram Weighted _ graph + create ( in n:Integer = 5 0 ) :Weighted _ graph + degree ( in n:Integer
Class Specification
UML Class Diagram
Weightedgraph
create in n:Integer :Weightedgraph
degree in n:Integer :Integer
edgecount:Integer
adjacent in m:Integer, in n:Integer :Real
distance in m:Integer, in n:Integer :Real
insert in m:Integer, in n:Integer, in w:Real
destroy
Description
This class allows the user to create and destroy an undirected weighted graph. You will be able
to find the shortest distance between two connected vertices. The vertices are numbered
through n where n is the argument to the constructor.
Member Variables
You may define whatever member variables you wish.
Member Functions
Constructors
Weightedgraph int n
Construct an undirected graph with n vertices by default, If n use n
Destructor
Clean up any allocated memory.Accessors
This class has three accessors:
int degree int n const
Returns the degree of the vertex n Throw an illegal argument exception if the argument
does not correspond to an existing vertex. O
int edgecount const
Returns the number of edges in the graph. O
double adjacent int m int n const
Returns the weight of the edge connecting vertices m and n If the vertices are the same,
return If the vertices are not adjacent, return infinity. Throw an illegal argument
exception if the arguments do not correspond to existing vertices.
Mutators
This class has two mutators:
void insert int m int n double w
If the weight w if it is infinity, throw an illegal argument exception. If the weight w
add an edge between vertices m and n If an edge already exists, replace the weight of
the edge with the new weight. If the vertices do not exist or are equal, throw an illegal
argument exception.
double distance int m int n
Return the shortest distance between vertices m and n Throw an illegal argument
exception if the arguments do not correspond to existing vertices. The distance between
a vertex and itself is The distance between vertices that are not connected is infinity. How do I implement double distanceint int function using priority queue?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
