Question

I need to develop a code of a graph in OOP and that can applied the...

I need to develop a code of a graph in OOP and that can applied the following algorithms! In python.

Create a Graph Class and code the following algorithms (python):
a. Breadth-First Search.
b. Depth-First Search.
c. Bellman-Ford Algorithm.
d. Dijkstra’s Algorithm.
e. Floyd-Warshall Algorithm

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Graph Creation and display in OOP

#include<iostream>
#include<stdlib.h>
using namespace std;

class graph
{
int g[20][20];

public:

graph()
{
}

void readgraph(int n)                   //input connected nodes of graph
{                           // and create adjacency matrix

   int i,j,c,k;
   for(i=0;i<n;i++)
   {
       for(j=0;j<n;j++)  
       {
           if(i==j)
           g[i][j]=0;
           else
           g[i][j]=99;
       }
  
   }
   cout<<"\n\t enter the nodes";
   do
   {
       cout<<"\n\t enter from node\t to node\t weight\n\t ";
       cin>>i;
       cout<<"\t ";
       cin>>j;
       cout<<"\t ";
       cin>>k;
       g[i][j]=k;
       g[j][i]=k;
       cout<<"\n\t add more nodes??\t 0 for yes\n\t ";
       cin>>c;
   }while(c==0);

}

                          
void printgraph(int n)                   //print adjacency matrix
{
int i,j;
   for(i=0;i<n;i++)
   {
       cout<<"\n";
       for(j=0;j<n;j++)
       {
       cout<<"\t "<<g[i][j];
       }

   }

}

Add a comment
Know the answer?
Add Answer to:
I need to develop a code of a graph in OOP and that can applied the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT