Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ class derived from GraphicInterface, as given in Listing 20-1. Use a

ID: 3582549 • Letter: W

Question

Write a C++ class derived from GraphicInterface, as given in Listing 20-1. Use an adjacency list NOT an adjacency matrix to represent the graph. Please include driver.

THANK YOU!

***Below is listing 20-1 if needed***

// Created by Frank M. Carrano and Timothy M. Henry.

// Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

// Listing 20-1.

/** An interface for the ADT undirected, connected graph.

@file GraphInterface.h */

#ifndef GRAPH_INTERFACE_

#define GRAPH_INTERFACE_

template<class LabelType>

class GraphInterface

{

public:

   /** Gets the number of vertices in this graph.

@return The number of vertices in the graph. */

   virtual int getNumVertices() const = 0;

   /** Gets the number of edges in this graph.

@return The number of edges in the graph. */

   virtual int getNumEdges() const = 0;

   /** Creates an undirected edge in this graph between two vertices

   that have the given labels. If such vertices do not exist, creates

   them and adds them to the graph before creating the edge.

@param start A label for the first vertex.

@param end A label for the second vertex.

@param edgeWeight The integer weight of the edge.

@return True if the edge is created, or false otherwise. */

   virtual bool add(LabelType start, LabelType end, int edgeWeight) = 0;

   /** Removes an edge from this graph. If a vertex is left with no other edges,

   it is removed from the graph since this is a connected graph.

@param start A label for the vertex at the beginning of the edge.

@param end A label for the vertex at the end of the edge.

@return True if the edge is removed, or false otherwise. */

   virtual bool remove(LabelType start, LabelType end) = 0;

   /** Gets the weight of an edge in this graph.

@param start A label for the vertex at the beginning of the edge.

@param end A label for the vertex at the end of the edge.

@return The weight of the specified edge.

   If no such edge exists, returns a negative integer. */

   virtual int getEdgeWeight(LabelType start, LabelType end) const = 0;

   /** Performs a depth-first search of this graph beginning at the given

   vertex and calls a given function once for each vertex visited.

@param start A label for the beginning vertex.

@param visit A client-defined function that performs an operation on

   or with each visited vertex. */

   virtual void depthFirstTraversal(LabelType start, void visit(LabelType&)) = 0;

   /** Performs a breadth-first search of this graph beginning at the given

   vertex and calls a given function once for each vertex visited.

@param start A label for the beginning vertex.

@param visit A client-defined function that performs an operation on

   or with each visited vertex. */

   virtual void breadthFirstTraversal(LabelType start, void visit(LabelType&)) = 0;

   /** Destroys this graph and frees its assigned memory. */

   virtual ~GraphInterface() { }

}; // end GraphInterface

#endif

Explanation / Answer

# define GRAPH _H

#define GRAPH_H

#include <vector>

#include <algorithm>

#include <iostream>

template <class T, bool directed> class Vertex

{

typedef typename std : : vector<T> : :size_type adjlist_sz;

   typedef Vertex<T, directed>* Edge;

public:

   Vertex() ;

Vertex(const vertex& v);

Vertex(const T& payload);

   Vertex<T, directed>& operator=(Vertex<T, directed> V);

   virtual ~Vertex();

void add_adj(Vertex<T , directed>& v);

   void remove_adj(Vertex<T, directed>& v);

   const bool is_adj_to(const Vertex<T, directed>& v);

   const T get_datnum();

   void set_datnum(const T& new_datnum);

   const adjlist_sz out_degree();

   inline friend void swap(Vertex<T, directed>& v1, Vertex<T, directed>& v2)

   {

   using std: : swap;

   swap(v1.datum, v2.datum);

swap(v1.adj_vertices, v2.adj_vertices);

   }

private :

   T datum;

std: : vector<Edge> adj_vertices;

   };

  template <class T, bool directed>

Vertex<T, directed>: : Vertex() : datum(T()), adj_vertices({ })

{

   std: :cout << "np ctor called" ;

}

template <class T, bool directed>

Vertex<T, directed>: : Vertex(const Veretex& v) : datum(v.get_datum()), adj_vertices({ ])

  {

   std: : cout << "copy-ctor called" ;

}

template <class T, bool directed>

Vertex<T, directed>: :Vertex(const T& payload) : datum(payload), adj_vertices({ })

{

   std : :cout << "payload ctor called";

}

template <class T, bool directed>

Vertex<T, directed> : :~Vertex()

{

   std: :cout << "dtor called";

   using std: : swap;

   std: :vector<Edge>().swap(adj_vertices);

  }

template < class T, bool directed>

Vertex<T, directed>& Vertex< T, directed> : : operator=(Vertex<T, directed> v)

{

   swap(*this, v);

   return * this;

}

template<class T, bool directed>

void Vertex<T, directed>: :add_adj(Vertex<T, directed>& v)

{

   adj_vertices.push_back(&v);

}

template<class T, bool directed?

void Vertex<T, directed>: : remove_adj(Vertex<T, directed>& v)

{

   std: : remove(adj_vertexs.begin(), adj_vertices.end(), &v);

}

template <class T, bool directed>

const bool Vertex<T, directed> : : is_adj_to(const Vertex<T, directed>& v)

{

   return std: : find( adj_vertices.begin(), adj_vertices.end(), &v ) !=adj_vertices.end;

}

template<class T, bool directed>

const T Vertex<T, directed> : : set_datum(const T& new_datum)

{

   datum = new_datum;

}

  template <class T, bool directed > class Graph

{

public :

   Graph();

   virtual ~Graph();

private:

   std: : vector<vector<T, directed> > vertices;

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote