Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void deleteCourse (Graph graph, int iVertex) This is invoked due to the DELETE c

ID: 3827619 • Letter: V

Question

void deleteCourse(Graph graph, int iVertex)

This is invoked due to the DELETE command. This will delete a course:

Because of the delete, this course will not be associated with any successors. (This also means that any successors will no longer have it as a prerequisite.)

Because of the delete, this course will not be associated with any prereqs. (This also means that no prereqs will have this course as a successor.)

Frees all edge nodes which reference this vertex.

The course is marked deleted in the vertex array.

As part of the extra credit, it is also removed from an overflow chain if it is in the overflow area.

Fix function:

void deleteCourse (Graph graph, int iVertex)//bExists
{
int i;
int j = 1;
if(graph == NULL)
{
printf("Delete Course graph NULL ");
return;
}
EdgeNode e = graph->vertexM[iVertex]->prereqList;
EdgeNode g = graph->vertexM[iVertex]->prereqList;

while(g != NULL)//traverses through prereqs
{
EdgeNode ps = graph->vertexM[g.iPrereqVertex]->successorList;
for(; ps != NULL; ps = ps->pNextEdge)//ps looks for successors in the prereqlist
{
   if(ps.iSuccVertex == iVertex)//checks for match
   {
   ps = NULL;
   break;
   }
}
g = g->pNextEdge;
}
e = graph->vertexM[iVertex]->successorList;
g = graph->vertexM[iVertex]->successorList;
while(g != NULL)//traverses through successors
{
ps = graph->vertexM[g.iSuccVertex]->prereqList;
for(; ps != NULL; ps = ps->pNextEdge)//ps looks for prereqs in the successorlist
{
if(ps.iSuccVertex == iVertex)//checks for match
{
ps = NULL;
break;
}
}
g = g->pNextEdge;
}
graph->vertexM[iVertex].bExists = FALSE;//Sets to FALSE (deleted)
}

Explanation / Answer

void deleteCourse (Graph graph, int iVertex)//bExists
{
int i;
int j = 1;
if(graph == NULL)
{
printf("Delete Course graph NULL ");
return;
}
EdgeNode e = graph->vertexM[iVertex]->prereqList;
EdgeNode g = graph->vertexM[iVertex]->prereqList;

while(g != NULL)//traverses through prereqs
{
EdgeNode ps = graph->vertexM[g.iPrereqVertex]->successorList;
for(; ps != NULL; ps = ps->pNextEdge)//ps looks for successors in the prereqlist
{
   if(ps.iSuccVertex == iVertex)//checks for match
   {
   ps = NULL;
   break;
   }
}
g = g->pNextEdge;
}
e = graph->vertexM[iVertex]->successorList;
g = graph->vertexM[iVertex]->successorList;
while(g != NULL)//traverses through successors
{
ps = graph->vertexM[g.iSuccVertex]->prereqList;
for(; ps != NULL; ps = ps->pNextEdge)//ps looks for prereqs in the successorlist
{
if(ps.iSuccVertex == iVertex)//checks for match
{
ps = NULL;
break;
}
}
g = g->pNextEdge;
}
graph->vertexM[iVertex].bExists = FALSE;//Sets to FALSE (deleted)
}