Commit e0b167bd authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Lab 5 done.

parent d112db29
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
//
// Created by Ari Trachtenberg on 11/1/24.
//

// Chapter 13

/**
 * A graph is a collection of vertices, together with edges connecting
 * some of the vertices.
 *
 * Implement a Graph class with the following properties:
 * -  There is only one public default constructor that produces an
 *    empty graph with no vertices (or edges).
 * -  operator+= is used to add a vertex with a given ID to the graph.
 *       if a vertex already has the given ID, a logic_error exception
 *       should be thrown.
 * -  hasEdge(int ID1, int ID2) returns true iff an edge between vertices
 *       with ids ID1 and ID2 exists.
 * -  addEdge(int ID1, int ID2) adds an edge between vertices with
 *       ids ID1 and ID2, respectively.
 *       if one of the IDs does not exist, or the edge already exists,
 *       an invalid_argument exception should be thrown.
 * -  operator[](int ii) returns the ii-th vertex in the graph (0-indexed)
 * -  numVertices() returns the number of vertices in the graph
 * -  numEdges() returns the number of edges in the graph
 *
 * @example
 * Graph G;
 * G+=3;
 * G+=5;
 * G+=3;            // throws logic_error
 * G.hasEdge(3,5);  // returns false
 * G.addEdge(5,3);  // adds an edge connecting vertex 5 and 3.
 * G.hasEdge(3,5);  // returns true (edge between 5 to 3 == between 3 and 5).
 * G[0];            // returns 3
 * G.numVertices(); // returns 2 - vertex ID 3 and ID 5
 * G.numEdges();    // returns 1 - between vertex ID 3 and ID 5
 */
class Graph;
 No newline at end of file