I just need the algorithm of the following C task Implement
I just need the algorithm of the following C++ task.
Implement the bucket algorithm using your implementation of the adjacency matrix. You
will read off the Graph from a text file holding vertex associations in every line of the graph
and populate or fill up your adjacency matrix before running the bucket algorithm on the
garph.
File contents can be like: (every line shows the the vertices with which edges are shared)
a has-edge g h d c e
b has-edge c f g e
c has-edge e f
d has-edge g c e
e has-edge a b c
f has-edge d e
g has-edge b c a
h has-edge d f e
First you will read this file and populate your adjacency matrix then run bucket algorithm
over it.
Solution
*
 * C++ Program to Implement Adjacency Matrix
 */
 #include <iostream>
 #include <cstdlib>
 using namespace std;
 #define MAX 20
 /*
 * Adjacency Matrix Class
 */
 class AdjacencyMatrix
 {
 private:
 int n;
 int **adj;
 bool *visited;
 public:
 AdjacencyMatrix(int n)
 {
 this->n = n;
 visited = new bool [n];
 adj = new int* [n];
 for (int i = 0; i < n; i++)
 {
 adj[i] = new int [n];
 for(int j = 0; j < n; j++)
 {
 adj[i][j] = 0;
 }
 }
 }
 /*
 * Adding Edge to Graph
 */
 void add_edge(int origin, int destin)
 {
 if( origin > n || destin > n || origin < 0 || destin < 0)
 {   
 cout<<\"Invalid edge!\ \";
 }
 else
 {
 adj[origin - 1][destin - 1] = 1;
 }
 }
 /*
 * Print the graph
 */
 void display()
 {
 int i,j;
 for(i = 0;i < n;i++)
 {
 for(j = 0; j < n; j++)
 cout<<adj[i][j]<<\" \";
 cout<<endl;
 }
 }
 };
 /*
 * Main
 */
 int main()
 {
 int nodes, max_edges, origin, destin;
 cout<<\"Enter number of nodes: \";
 cin>>nodes;
 AdjacencyMatrix am(nodes);
 max_edges = nodes * (nodes - 1);
 for (int i = 0; i < max_edges; i++)
 {
 cout<<\"Enter edge (-1 -1 to exit): \";
 cin>>origin>>destin;
 if((origin == -1) && (destin == -1))
 break;
 am.add_edge(origin, destin);
 }
 am.display();
 return 0;
 }


