Advertisement
RIck687

cs2123p5.h

Apr 17th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. /**********************************************************************
  2. cs2123p5.h
  3. Purpose:
  4. Defines constants:
  5. max constants
  6. error constants
  7. warning constants
  8. boolean constants
  9. Defines typedef for
  10. EdgeNode - graph edge containing preq and successor vertex
  11. Vertex - contains course information (course number, name), existence boolean,
  12. successor list first node pointer, predecessor list first node pointer
  13. GraphImp - array of vertices and a count of them
  14. Graph - pointer to an allocated GraphImp
  15. PlanImp - tbd
  16. Defines function prototypes for functions used in pgm5 (recursive and non-recursive)
  17. Defines function prototypes for functions used in pgm6
  18. Defines WARNING macro
  19. Notes:
  20.  
  21. **********************************************************************/
  22. /*** constants ***/
  23. #define MAX_TOKEN 50 // Maximum number of actual characters for a token
  24. #define MAX_LINE_SIZE 100 // Maximum number of character per input line
  25. #define MAX_VERTICES 70
  26. // Error constants (program exit values)
  27. #define ERR_COMMAND_LINE 900 // invalid command line argument
  28. #define ERR_ALGORITHM 903 // Unexpected error in algorithm
  29.  
  30. #define ERR_TOO_MANY_COURSE 1 // Too many courses
  31. #define ERR_BAD_COURSE 3 // Bad Course Data
  32. #define ERR_BAD_PREREQ 4 // Bad Prereq Data
  33. #define ERR_MISSING_SWITCH "missing switch"
  34. #define ERR_EXPECTED_SWITCH "expected switch, found"
  35. #define ERR_MISSING_ARGUMENT "missing argument for"
  36.  
  37. // exitUsage control
  38. #define USAGE_ONLY 0 // user only requested usage information
  39. #define USAGE_ERR -1 // usage error, show message and usage information
  40.  
  41. // boolean constants
  42. #define FALSE 0
  43. #define TRUE 1
  44.  
  45. // EdgeNode represents one edge in a graph
  46. typedef struct EdgeNode
  47. {
  48. int iPrereqVertex; // prereq
  49. int iSuccVertex; // successor
  50. struct EdgeNode *pNextEdge; // points to next edge
  51. } EdgeNode;
  52.  
  53.  
  54. typedef struct Vertex
  55. {
  56. char szCourseId[8]; // Course Identifier
  57. char szCourseName[21]; // Course Full Name
  58. char szDept[4]; // Department (e.g., CS, MAT)
  59. int bExists; // pgm6 DELETE command causes this to be set to TRUE
  60. // TRUE - this vertex exists, FALSE - deleted
  61. EdgeNode * prereqList;
  62. EdgeNode * successorList;
  63. int iSemesterLevel;
  64. int iHashChainNext; // pgm 6 extra credit
  65. int iDistSource;
  66. } Vertex;
  67.  
  68. // GraphImp of a double adjacency list graph
  69. typedef struct
  70. {
  71. int iNumVertices;
  72. Vertex vertexM[MAX_VERTICES];
  73. } GraphImp;
  74.  
  75. typedef GraphImp *Graph;
  76.  
  77. // Degree Plan
  78.  
  79. typedef struct
  80. {
  81. int semesterM[5][MAX_VERTICES];
  82. int bIncludeM[MAX_VERTICES];
  83. } PlanImp;
  84. typedef PlanImp * Plan;
  85.  
  86. typedef struct
  87. {
  88. int iPrimayMax ; // Max subscript in the primary portion
  89. // Any subscript higher is in overflow
  90. } HashTable;
  91.  
  92. // Prototypes
  93.  
  94. // Extra functions made by students (if anything)
  95. void processInput(Graph graph);
  96. void processCommands(Graph graph, char szCommand[], char pszRemainingTxt[]);
  97. void insertVertexCourse(Graph graph, char szCourseId[], char szName[]);
  98. void insertToHeadOfList(EdgeNode **list, EdgeNode *pEdge);
  99. EdgeNode * newEdgeNode(int iPrereqVertex, int iSuccVertex);
  100. int checkList(EdgeNode *list, int iVertex);
  101.  
  102. // Recursive functions for program 5
  103. int maxChainLength(Graph graph, int iVertex);
  104. void printTraversal(Graph graph, int iCourseVertex, int indent);
  105. void printLongChains(Graph graph, int iVertex, int pathM[], int iLevel, int iLongLength);
  106. int causesCycle(Graph graph, int iPrereqVertex, int iVertex);
  107.  
  108. // Non-recursive for program 5
  109. int findCourse(Graph graph, char szCourseId[]);
  110. void insertPrereq(Graph graph, int iPrereqVertex, int iCourseVertex);
  111. void printAllInList(Graph graph);
  112. void printOne(Graph graph, int iVertex);
  113. void printSources(Graph graph);
  114. void printSinks(Graph graph);
  115.  
  116. Graph newGraph();
  117.  
  118. // Program 6 function for delete
  119. void deleteCourse (Graph graph, int iVertex);
  120.  
  121. // Program 6 functions for Plan
  122. void doPlan(Graph graph, Plan plan);
  123. void setLevel(Graph g, Plan plan, int iVertex, int iLev);
  124. Plan newPlan();
  125.  
  126. // functions in most programs, but require modifications
  127. void processCommandSwitches(int argc, char *argv[], char **ppszCommandFileName);
  128. void exitUsage(int iArg, char *pszMessage, char *pszDiagnosticInfo);
  129.  
  130. // Utility routines provided by Larry
  131. void ErrExit(int iexitRC, char szFmt[], ...);
  132. char * getToken(char *pszInputTxt, char szToken[], int iTokenSize);
  133.  
  134.  
  135. /*
  136. WARNING macro
  137. Parameters:
  138. I szFmt - a printf format
  139. I ... - a variable number of parameters corresponding to szFmt's
  140. format codes.
  141. Results:
  142. Prints "WARNING" and the value(s) specified by the szFmt.
  143. Notes:
  144. Since this generates multiple C statements, we surround them
  145. with a dummy do while(0) which only executes once. Notice that the
  146. dummy do while isn't ended with a ";" since the user of
  147. the macro naturally specifies a ";". Example:
  148. if (x != 0)
  149. WARNING("X must be blah blah");
  150. else
  151. { // normal processing
  152. ....
  153. }
  154. If we used {} in the macro definition instead of the dummy do while(0),
  155. the generated code would have a bad ";":
  156. if (x != 0)
  157. {
  158. printf("\tWARNING: ");
  159. printf("X must be blah blah");
  160. printf("\n");
  161. } ; // yuck, bad ";" causing the compiler to not understand the else
  162. else
  163. { // normal processing
  164. ....
  165. }
  166.  
  167. #define WARNING(szFmt, ...) do {
  168. printf("\tWARNING: ");
  169. printf(szFmt, __VA_ARGS__);
  170. printf("\n");
  171. } while (0)*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement