Complete the code to declare a graph vertex structure with an integer id.
typedef struct Vertex {
int [1];
} Vertex;The vertex structure should have an integer id to uniquely identify it.
Complete the code to declare an edge structure with source and destination vertices.
typedef struct Edge {
int source;
int [1];
} Edge;The edge connects a source vertex to a destination vertex.
Fix the error in the code to correctly declare a weighted edge structure.
typedef struct WeightedEdge {
int source;
int destination;
float [1];
} WeightedEdge;The field representing the edge's weight should be named weight.
Fill both blanks to complete the function that checks if a graph is directed or undirected based on edges.
int isDirectedGraph(Edge edges[], int n) {
for (int i = 0; i < n; i++) {
int src = edges[i].source;
int dest = edges[i].[1];
int found = 0;
for (int j = 0; j < n; j++) {
if (edges[j].source == dest && edges[j].[2] == src) {
found = 1;
break;
}
}
if (!found) return 1; // Directed
}
return 0; // Undirected
}The function compares edges by their destination and source fields to check for reverse edges.
Fill all three blanks to complete the function that creates a weighted edge and assigns values.
WeightedEdge createWeightedEdge(int [1], int [2], float [3]) { WeightedEdge e; e.source = [1]; e.destination = [2]; e.weight = [3]; return e; }
The function parameters are named src, dest, and w to assign source, destination, and weight respectively.