In: Computer Science
Using C++:
Create a function to search an undirected weighted graph and find the highest weighted edge between two specific values.
This should include a class declaration and the definition for all required members that are needed to support the search. NO NEED to code those members. You can assume any other data structures such as stack, heap, or linked list is defined (so you can use their standard functions without declaring or defining them).
#include <bits/stdc++.h>
#include <limits.h>
using namespace std;
#define n 6
class graph
{
private:
int g[n][n];
public:
int search()
{
int max=INT_MIN;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(g[i][j]>max)max=g[i][j];
}
}
return max;
}
void initialize()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
g[i][j]=0;
}
}
return ;
}
void addEdge(int x, int y,int w)
{
g[x][y]=w;
g[y][x]=w;
}
};
int main()
{
graph gra;
gra.initialize();
gra.addEdge(0,2,4);
gra.addEdge(3,2,2);
gra.addEdge(5,4,6);
gra.addEdge(1,4,9);
gra.addEdge(2,3,6);
gra.addEdge(5,3,7);
cout<<"The maximum weight of the edge is
"<<gra.search();
return 0;
}
PLEASE DO UPVOTE IF THE ANSWER IS HELPFUL , AS IT GIVES CONFIDENCE TO HELP MORE STUDENTS