#include #include #include #include #include "Graph.h" #include "GraphAdjListRep.h" #include "graphReader.h" #include "Queue.h" int largestComponent(Graph g, int component[]); void sort(int arr[], int size); int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]); exit(EXIT_FAILURE); } char *graphFile = argv[1]; Graph g = readGraph(graphFile); printf("-----\n"); printf("Graph\n"); printf("-----\n"); GraphShow(g); printf("\n"); int *component = calloc(GraphNumVertices(g), sizeof(int)); if (component == NULL) { fprintf(stderr, "error: out of memory\n"); exit(EXIT_FAILURE); } int compSize = largestComponent(g, component); sort(component, compSize); printf("Largest component contains %d %s:", compSize, compSize == 1 ? "vertex" : "vertices"); for (int i = 0; i < compSize; i++) { printf(" %d", component[i]); } printf("\n"); GraphFree(g); free(component); return 0; } // !!! DO NOT MODIFY THE CODE ABOVE !!! // (unless you are adding function prototypes) //////////////////////////////////////////////////////////////////////// // Your task int largestComponent(Graph g, int component[]) { // TODO return 0; } //////////////////////////////////////////////////////////////////////// // !!! DO NOT MODIFY THE CODE BELOW !!! void sort(int arr[], int size) { for (int i = 0; i < size - 1; i++) { int min = i; for (int j = i + 1; j < size; j++) { if (arr[j] < arr[min]) { min = j; } } int tmp = arr[i]; arr[i] = arr[min]; arr[min] = tmp; } }