Question
I need help with this function: int maxChainLength (Graph graph, int iVertex); The function has to returns the count of the number of vertices in
I need help with this function: int maxChainLength(Graph graph, int iVertex); The function has to returns the count of the number of vertices in the longest chain that begins with the specified vertex. The function also has to be recursive.
For example, if it starts at CS1083 and goes through the graph and should return 4 because the longest chain is CS1083 through CS373 or cs3733 or cs3433.
This is all I have right now:
int findCourse(Graph graph, char szCourseId[])
{
//int to be used in the for loop
int i;
//goes through the specified array to find the course id
for(i = 0; i iNumVertices; i++)
{
//if its found it returns i
if(strcmp(graph->vertexM[i].szCourseId, szCourseId)== 0)
return i;
}
return -1;
}
// int ivertex = findCourse(Graph graph, courseID[ ])
int maxChain(Graph graph, int iVertex){ //
EdgeNode *e;
int iCount;
for(e = graph->vertexM[iVertex].successorList; e != NULL; e = e->pNextEdge){ // The for loop goes through the entire graph.
maxChain(graph, e->iSuccVertex);
}
return iCount;
}
header file:
// EdgeNode represents one edge in a graph
typedef struct EdgeNode
{
int iPrereqVertex; // prereq
int iSuccVertex; // successor
struct EdgeNode *pNextEdge; // points to next edge
} EdgeNode;
typedef struct Vertex
{
char szCourseId[8]; // Course Identifier
char szCourseName[21]; // Course Full Name
char szDept[4]; // Department (e.g., CS, MAT)
int bExists; // pgm6 DELETE command causes this to be set to TRUE
// TRUE - this vertex exists, FALSE - deleted
EdgeNode * prereqList; // badically means it is going to go backwards when pNextEdge
EdgeNode * successorList; //means it is going forward when pNextEdge
int iSemesterLevel;
int iHashChainNext; // pgm 6 extra credit
int iDistSource;
} Vertex;
// GraphImp of a double adjacency list graph
typedef struct
{
int iNumVertices;
Vertex vertexM[MAX_VERTICES];
} GraphImp;
typedef GraphImp *Graph;
) | > math1224Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started