Question: Code following functions in C void printLongChains (Graph graph, int iVertex, int pathM[], int iLevel, int iLongLength) Prints each chain that is the the longest
Code following functions in C
void printLongChains(Graph graph, int iVertex, int pathM[], int iLevel, int iLongLength)
Prints each chain that is the the longest chain of courses and prerequisites beginning at the specified course.
Parameters:
iVertex - begins with a starting vertex from which we want to print its longest chains. On subsequent calls, this is a successor vertex.
pathM[] - an array representing the path from the original starting vertex to the current vertex
iLevel - on each recursive call of printLongChains, this increases. It is used as the subscript into pathM[]. It is also used to test whether we reached iMaxLength.
iLongLength - known longest chain length
void printTraversal(Graph graph, int iVertex, int iIndent)
This is invoked due to the PRTSUCC command. printTraversal is a recursive function which prints the current vertex information (course ID, course Name) and then uses a depth first traversal to indent and print the successors.
/********************************************************************** cs2123p5.h Purpose: Defines constants: max constants error constants warning constants boolean constants Defines typedef for EdgeNode - graph edge containing preq and successor vertex Vertex - contains course information (course number, name), existence boolean, successor list first node pointer, predecessor list first node pointer GraphImp - array of vertices and a count of them Graph - pointer to an allocated GraphImp PlanImp - tbd Defines function prototypes for functions used in pgm5 (recursive and non-recursive) Defines function prototypes for functions used in pgm6 Defines WARNING macro Notes: **********************************************************************/ /*** constants ***/ #define MAX_TOKEN 50 // Maximum number of actual characters for a token #define MAX_LINE_SIZE 100 // Maximum number of character per input line #define MAX_VERTICES 70 // Error constants (program exit values) #define ERR_COMMAND_LINE 900 // invalid command line argument #define ERR_ALGORITHM 903 // Unexpected error in algorithm #define ERR_TOO_MANY_COURSE 1 // Too many courses #define ERR_BAD_COURSE 3 // Bad Course Data #define ERR_BAD_PREREQ 4 // Bad Prereq Data #define ERR_MISSING_SWITCH "missing switch" #define ERR_EXPECTED_SWITCH "expected switch, found" #define ERR_MISSING_ARGUMENT "missing argument for" // exitUsage control #define USAGE_ONLY 0 // user only requested usage information #define USAGE_ERR -1 // usage error, show message and usage information // boolean constants #define FALSE 0 #define TRUE 1 // 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; EdgeNode * successorList; 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; // Degree Plan typedef struct { int semesterM[5][MAX_VERTICES]; int bIncludeM[MAX_VERTICES]; } PlanImp; typedef PlanImp * Plan; typedef struct { int iPrimayMax ; // Max subscript in the primary portion // Any subscript higher is in overflow } HashTable; // Prototypes // Recursive functions for program 5 int maxChain(Graph graph, int iVertex); void printTraversal(Graph graph, int iCourseVertex, int indent); void printLongChains(Graph graph, int iVertex, int pathM[], int iLevel, int iLongLength); int causesCycle(Graph graph, int iPrereqVertex, int iVertex); // Non-recursive for program 5 int findCourse(Graph graph, char szCourseId[]); void insertPrereq(Graph graph, int iPrereqVertex, int iCourseVertex); void printAllInList(Graph graph); void printOne(Graph graph, int iVertex); void printSources(Graph graph); void printSinks(Graph graph); Graph newGraph(); // Program 6 function for delete void deleteCourse (Graph graph, int iVertex); // Program 6 functions for Plan void doPlan(Graph graph, Plan plan); void setLevel(Graph g, Plan plan, int iVertex, int iLev); Plan newPlan(); // functions in most programs, but require modifications void processCommandSwitches(int argc, char *argv[], char **ppszCommandFileName); void exitUsage(int iArg, char *pszMessage, char *pszDiagnosticInfo); // Utility routines provided by Larry void ErrExit(int iexitRC, char szFmt[], ...); char * getToken(char *pszInputTxt, char szToken[], int iTokenSize); /* WARNING macro Parameters: I szFmt - a printf format I ... - a variable number of parameters corresponding to szFmt's format codes. Results: Prints "WARNING" and the value(s) specified by the szFmt. Notes: Since this generates multiple C statements, we surround them with a dummy do while(0) which only executes once. Notice that the dummy do while isn't ended with a ";" since the user of the macro naturally specifies a ";". Example: if (x != 0) WARNING("X must be blah blah"); else { // normal processing .... } If we used {} in the macro definition instead of the dummy do while(0), the generated code would have a bad ";": if (x != 0) { printf("\tWARNING: "); printf("X must be blah blah"); printf(" "); } ; // yuck, bad ";" causing the compiler to not understand the else else { // normal processing .... } */ #define WARNING(szFmt, ...) do { \ printf("\tWARNING: "); \ printf(szFmt, __VA_ARGS__); \ printf(" "); \ } while (0) //Input file COURSE CS1083 Intro I COURSE CS1713 Intro II PREREQ CS1083 COURSE CS2123 Data Structures PREREQ CS1713 PRTONE CS2123 PRTONE CS1713 PRTALL COURSE MAT1214 Calculus I COURSE MAT1224 Calculus II PREREQ MAT1214 COURSE MAT2233 Discrete Math PREREQ MAT1214 PREREQ CS1713 COURSE MAT3333 Math Found PREREQ MAT1224 PREREQ CS1713 COURSE CS3343 Analysis of Algo PREREQ CS2123 PREREQ MAT3333 PREREQ MAT2233 * * show some chains * PRTSUCC CS1083 MAXCHAIN CS1083 PRTLONGS CS1083 * * More core courses * COURSE CS3423 Sys Pgm PREREQ CS2123 COURSE CS3433 Princ of Security PREREQ CS3423 COURSE CS3443 App Pgm PREREQ CS2123 COURSE CS3843 Comp Org PREREQ CS2123 COURSE CS3723 Pgm Lang PREREQ CS3443 PREREQ MAT2233 COURSE CS3733 Operating Systems PREREQ CS3423 PREREQ CS3443 PREREQ CS3843 PRTALL PRTSUCC CS1713 MAXCHAIN CS1713 PRTLONGS CS1713 PRTSUCC MAT1214 MAXCHAIN MAT1214 PRTLONGS MAT1214 * * Insert all the other courses * COURSE CS3743 Database Systems PREREQ CS3423 PREREQ CS3753 COURSE CS3753 Intro Data Sci PREREQ CS2123 PREREQ MAT2233 PREREQ MAT3333 COURSE CS3773 Software Engineering PREREQ CS3443 COURSE CS3793 Artificial Intel PREREQ CS3343 COURSE CS3853 Computer Arch PREREQ CS3843 PREREQ CS3423 COURSE CS3873 Networks PREREQ CS3843 COURSE CS4223 Bioinformatics PREREQ CS3753 COURSE CS4233 Computational Bio PREREQ CS3753 COURSE CS4353 Unix & Net Security PREREQ CS3433 COURSE CS4363 Cryptography PREREQ CS3343 PREREQ CS3433 COURSE CS4373 Data Mining PREREQ CS3743 COURSE CS4393 User Interfaces PREREQ CS3443 COURSE CS4413 Web PREREQ CS3423 COURSE CS4633 Simulation PREREQ CS3343 COURSE CS4633 Mobile Tech PREREQ CS3733 COURSE CS4663 Dist Cloud Security PREREQ CS3733 COURSE CS4673 Cyber Operations PREREQ CS4353 COURSE CS4713 Compiler Construct PREREQ CS3723 PREREQ CS3843 COURSE CS4723 Sw Valid & QA PREREQ CS3773 COURSE CS4733 Project Mgt PREREQ CS3773 COURSE CS4743 Enterprise Sw Eng PREREQ CS3773 COURSE CS4783 Adv Sw Eng PREREQ CS3773 COURSE CS4823 Parallel Programming PREREQ CS3343 PREREQ CS3423 COURSE CS4843 Cloud Computing PREREQ CS3423 PREREQ CS3853 COURSE CS4973 Big Data PREREQ CS3743 * * End of all the courses * PRTALL * * cycle stuff * PRTSUCC CS3443 COURSE CS3443 Appl Pgm PREREQ MAT1214 PREREQ CS4713 * * Final Output from program 5 * PRTSUCC CS1083 PRTSUCC MAT1214 PRTSOURCES PRTSINKS PRTALL MAXCHAIN CS2123 PRTLONGS CS2123
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
