Question

Implement an undirected Graph class that contains the following methods: 1. addEdge 2. removeEdge 3. isEdge

Implement an undirected Graph class that contains the following methods:

1. addEdge

2. removeEdge

3. isEdge

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

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Please note below is the class only as asked by your question

public class Graph {

      private boolean adjacencyMatrix[][];

      private int vertexCount;

      public Graph(int vertexCount) {

            this.vertexCount = vertexCount;

            adjacencyMatrix = new boolean[vertexCount][vertexCount];

      }

      public void addEdge(int i, int j) {

            if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount) {

                  adjacencyMatrix[i][j] = true;

                  adjacencyMatrix[j][i] = true;

            }

      }

      public void removeEdge(int i, int j) {

            if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount) {

                  adjacencyMatrix[i][j] = false;

                  adjacencyMatrix[j][i] = false;

            }

      }

      public boolean isEdge(int i, int j) {

            if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount)

                  return adjacencyMatrix[i][j];

            else

                  return false;

      }

}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Implement an undirected Graph class that contains the following methods: 1. addEdge 2. removeEdge 3. isEdge
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