The task is to implement a directed_graph class, where each node/edge has a weight.
The class should offer a reasonably effective suite of operations. Some (but not all) of basic operations are:
Adding and removing nodes and edges (with weights);
Depth-first and breadth-first traversals;
Computing the minimum spanning tree (MST);
Pre-order, in-order, and post-order traversals of the MST
#ifndef DIRECTED_GRAPH_H
#define DIRECTED_GRAPH_H
#include
#include
#include
// include more libraries here if you need to
using namespace std; // the standard namespace are here just in case.
/*
the vertex class
*/
template
class vertex {
public:
int id;
T weight;
vertex(int x, T y) : id(x), weight(y) {}
// add more functions here if you need to
};
/*
the graph class
*/
template
class directed_graph {
private:
//You will need to add some data members here
//to actually represent the graph internally,
//and keep track of whatever you need to.
public:
directed_graph(); //A constructor for directed_graph. The graph should start empty.
~directed_graph(); //A destructor. Depending on how you do things, this may not be necessary.
bool contains(const int&) const; //Returns true if the graph contains the given vertex_id, false otherwise.
bool adjacent(const int&, const int&) const; //Returns true if the first vertex is adjacent to the second, false otherwise.
void add_vertex(const vertex&); //Adds the passed in vertex to the graph (with no edges).
void add_edge(const int&, const int&, const T&); //Adds a weighted edge from the first vertex to the second.
void remove_vertex(const int&); //Removes the given vertex. Should also clear any incident edges.
void remove_edge(const int&, const int&); //Removes the edge between the two vertices, if it exists.
size_t in_degree(const int&) const; //Returns number of edges coming in to a vertex.
size_t out_degree(const int&) const; //Returns the number of edges leaving a vertex.
size_t degree(const int&) const; //Returns the degree of the vertex (both in edges and out edges).
size_t num_vertices() const; //Returns the total number of vertices in the graph.
size_t num_edges() const; //Returns the total number of edges in the graph.
vector get_vertices(); //Returns a vector containing all the vertices.
vector get_neighbours(const int&); //Returns a vector containing all the vertices reachable from the given vertex. The vertex is not considered a neighbour of itself.
vector get_second_order_neighbours(const int&); // Returns a vector containing all the second_order_neighbours (i.e., neighbours of neighbours) of the given vertex.
// A vector cannot be considered a second_order_neighbour of itself.
bool reachable(const int&, const int&) const; //Returns true if the second vertex is reachable from the first (can you follow a path of out-edges to get from the first to the second?). Returns false otherwise.
bool contain_cycles() const; // Return true if the graph contains cycles (there is a path from any vertices directly/indirectly to itself), false otherwise.
vector depth_first(const int&); //Returns the vertices of the graph in the order they are visited in by a depth-first traversal starting at the given vertex.
vector breadth_first(const int&); //Returns the vertices of the graph in the order they are visisted in by a breadth-first traversal starting at the given vertex.
directed_graph out_tree(const int&); //Returns a spanning tree of the graph starting at the given vertex using the out-edges. This means every vertex in the tree is reachable from the root.
vector pre_order_traversal(const int&, directed_graph&); // returns the vertices in the visiting order of a pre-order traversal of the minimum spanning tree starting at the given vertex.
vector in_order_traversal(const int&, directed_graph&); // returns the vertices in the visiting order of an in-order traversal of the minimum spanning tree starting at the given vertex.
vector post_order_traversal(const int&, directed_graph&); // returns the vertices in ther visitig order of a post-order traversal of the minimum spanning tree starting at the given vertex.
vector significance_sorting(); // Return a vector containing a sorted list of the vertices in descending order of their significance.
};
// Define all your methods down here (or move them up into the header, but be careful you don't double up). If you want to move this into another file, you can, but you should #include the file here.
// Although these are just the same names copied from above, you may find a few more clues in the full method headers.
// Note also that C++ is sensitive to the order you declare and define things in - you have to have it available before you use it.
88 Answers
20 Answers
DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Functions and Arrays – to solve computationalproblems.Arrays provide a convenient way to store &
The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is anPath finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going through certain obstacles. As the main aim is to thinkabout path finding, we focus on the common task
Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individualDevelop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. TheLineItem class will represent an individual line item of merchandise that acustomer is purchasing.
SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define: SeaPortProgram e
Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define: SeaPortProgram e
The first programming project involves writing a program that parses, using recursive descent, a GUI definition language defined in an input file and generates the GUI that it defines. The grammar for this language is defined below:1Project 1The first programming project involves writing a program that parses, using recursive descent, a GUIdefinition language defined in an input file and generates the GUI that it defines. The grammar for thislanguage is defined below:gui ::= Wi
CMSC 335 Project SeaPort Solved Project 3 Introduction the SeaPort Project series For this set of projects for the course we wish to simulate some of the aspects of a number of Sea PortsCMSC 335 Project SolvedProject 3 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:
CMSC 335 Project 4 Solved SeaPort Introduction the SeaPort Project series For this set of projects for the course we wish to simulate some of the aspects of a number of Sea Ports Here are the classes and their instance variables we wish to defineProject 4 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define: SeaPortProgram ext
CMSC 451 Project 2 Solved The second project involves completing and extending the C++ program that evaluates statements of an expression language contained in the module 3 case studyProject 2 The second project involves completing and extending the C++ program that evaluates statements of an expression language contained in the module 3 case study. The statements of that expression language consist of an arithmetic expression f
CMSC 451 Project 1 Solved The first project involves benchmarking the behavior of Java implementations of one of the following sorting algorithms bubble sort selection sort insertion sort Shell sort, merge sort quick sort or heap sortCMSC 451 Project 1The first project involves benchmarking the behavior of Java implementations of one of thefollowing sorting algorithms, bubble sort, selection sort, insertion sort, Shell sort, merge sort,quick sort or heap sort. You must post your
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.
Get Free Quote!
252 Experts Online