Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- // data structure to store graph edges
- struct Edge {
- int src, dest;
- };
- // class to represent a graph object
- class Graph
- {
- public:
- // construct a vector of vectors to represent an adjacency list
- vector<vector<int>> adjList;
- // Graph Constructor
- Graph(vector<Edge> const &edges, int N)
- {
- // resize the vector to N elements of type vector<int>
- adjList.resize(N);
- // add edges to the directed graph
- for (auto &edge : edges)
- {
- // insert at the end
- adjList[edge.src].push_back(edge.dest);
- // Uncomment below line for undirected graph
- // adjList[edge.dest].push_back(edge.src);
- }
- }
- };
- // print adjacency list representation of graph
- void printGraph(Graph const& graph, int N)
- { //prints the header
- for (char col = 'A'; col <= 'H'; col++)
- {
- cout << col << " ";
- }
- cout << endl;
- int linearindex=0;
- for (int row = 1; row <= 1; row++)
- {
- for (char col = 1; col <= 8; col++)
- {
- //cout << col << " ";
- vector<int> v = graph.adjList[linearindex+col];
- for (int n : v)
- {
- cout << n << " " ;
- }
- }
- linearindex += 8;
- cout << endl;
- }
- for (int i = 0; i < N; i++)
- {
- // print current vertex number
- //cout << i << " --> ";
- // print all neighboring vertices of vertex i
- //for (int v : graph.adjList[i])
- //cout << v << " ";
- //cout << endl;
- }
- }
- // Graph Implementation using STL
- int main()
- {
- // vector of graph edges as per above diagram.
- // Please note that initialization vector in below format will
- // work fine in C++11, C++14, C++17 but will fail in C++98.
- int row;
- int col;
- string entry;
- for (;;)
- {
- cout << "Please enter row: ";
- cin >> row;
- cout << "enter col";
- cin >> col;
- cout << "";
- }
- vector<Edge> edges =
- {
- { 0, 1 }, { 1, 2 }, { 2, 0 }, { 2, 1 },
- { 3, 2 }, { 4, 5 }, { 5, 4 }, {6, 7}
- };
- vector<Edge> x = { { 0, 0 } };
- //std::fill(edges.begin(), edges.end(), x);
- // Number of nodes in the graph
- int N = 160;
- // construct graph
- Graph graph(edges, N);
- // print adjacency list representation of graph
- printGraph(graph, N);
- system("pause");
- return 0;
- }
- // Get input A1 10
- //See the function.
- //Find sum function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement