Question: WRITE C + + CODE. NO INSTRUCTIONS. Complete my C + + code and make it run. Do what is necessary even deleting portions of

WRITE C++ CODE. NO INSTRUCTIONS. Complete my C++ code and make it run. Do what is necessary even deleting portions of code to ensure it works. Make sure it also adhears to the instructions and provides the sample output.
#include
#include
#include
using namespace std;
#define UNVISITED 0
#define VISITED 1
const int defaultSize =10;
// Big enough for simple testing
#define INFINITE 9999
int minVertex(Graph* G, int* D){// Find min cost vertex
int i, v =-1;
// Initialize v to some unvisited vertex
for (i =0; i G->NumVertices(); i++)
{
if (G->getMark(i)== UNVISITED)
{
v = i; break;
}
}
for (i++; i G->NumVertices(); i++)// Now find smallest D value
{
if ((G->getMark(i)== UNVISITED) && (D[i] D[v]))
v = i;
}
return v;
}
void Prim(Graph* G, int* D, int s)
{
int* V = new int[G->NumVertices()];
int i, w;
for (int i =0; i G->NumVertices(); i++)
D[i]= INFINITE;
D[s]=0;
for (i =0; i G->NumVertices(); i++)
{
int v = minVertex(G, D);
G->setMark(v, VISITED);
if (v != s)
G->AddEdgetoMST(V[v], v);
if (D[v]== INFINITE)
return;
for (w = G->first(v); w G->NumVertices(); w = G->next(v, w))
{
if (D[w]> G->weight(v, w))
{
D[w]= G->weight(v, w);
V[w]= v;
}
}
}
// sets graph matrix
setMatrix(G, s, D, V);
delete[] V;
}
void setMatrix(Graph* graph, int start, int* weights, int* vertices)
{
int less = INFINITE;
int index =0;
// increment through each row
for (int row =0; row graph->NumVertices(); row++)
{
// if current row == starting row
if (row != start)
{
// go to each item in the row (past the diagonal)
for (int col = row +1; col graph->NumVertices(); col++)
{
// if stored closest vertex == current vertex && !=0
if (vertices[row]== col && vertices[row]>0)
graph->setEdge(row, col, weights[row]);
else
{
graph->deleteEdge(row, col);
graph->deleteEdge(col, row);
}
}
}
// if current row == starting row
else
{
for (int col = row; col graph->NumVertices(); col++)
{
// if least needs to be updated
if (less > graph->weight(row, col) &&
graph->weight(row, col)!=0)
{
less = graph->weight(row, col);
index = col;
}
// if less is less than current item weight
else if (less graph->weight(row, col))
{
// if less current item, delete item and it's mirror
graph->deleteEdge(row, col);
graph->deleteEdge(col, row);
}
}
// deletes values before less
for (int p = row; p index; p++)
{
if (less != graph->weight(p, row))
{
graph->deleteEdge(row, p);
graph->deleteEdge(p, row);
}
}
// set the edge
graph->setEdge(row, index, less);
}
}
}
GraphM.h
#include "MST.h"
#include "Graph.h"
#include
#include
using namespace std;
class GraphM : public Graph
{
private:
int numVertex, numEdge;
int** matrix;
int* mark;
public:
GraphM(int numVert)
{
Init(numVert);
}
~GraphM()
{
delete[] mark;
for (int i =0; i numVertex; i++)
delete[] matrix[i];
delete[] matrix;
}
void Init(int n)
{
int i;
numVertex = n;
numEdge =0;
mark = new int[n];
for (i =0; i numVertex; i++)
mark[i]= UNVISITED;
matrix =(int**) new int*[numVertex];
for (i =0; i numVertex; i++)
matrix[i]= new int[numVertex];
for (i =0; i numVertex; i++)
for (int j =0; j numVertex; j++)
matrix[i][j]=0;
}
int NumVertices(){ return numVertex; }
int NumEdges(){ return numEdge; }
// Return first neighbor of "v"
int first(int v)
{
for (int i =0; i numVertex; i++)
if (matrix[v][i]!=0)
return i;
return numVertex;
}
// Return vs next neighbor after w
int next(int v, int w)
{
for (int i = w +1; i numVertex; i++)
if (matrix[v][i]!=0)
return i;
return numVertex;
WRITE C + + CODE. NO INSTRUCTIONS. Complete my C

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!