Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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;

) | > math1224

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

1. List the basic factors determining pay rates.pg 87

Answered: 1 week ago