Hey, I'm picking up C++ by translating java code to C++. Currently I'm working on translating dijkstra's algorithm. I have the completed code in java and it works perfectly. I need some help with the C++ syntax. I'm not going to paste the whole code, this is a part of what I have:
Code:
class Graph
{
final int MAX_VERTS = 20;
final int INFINITY = 1000000;
Vertex vertexList[]; //list of vertices
int adjMat[][]; //adjacency matrix
int nVerts; //current number of vertices
int nTree; //number of vertices in tree
DistPar sPath[]; //array for shortest-path data
int currentVert; //current vertex
int startToCurrent; //distance to currentVert
//-----------------------------------------------------------------------------------
public Graph() //constructor
{
vertexList = new Vertex[MAX_VERTS];
adjMat = new int[MAX_VERTS][MAX_VERTS];
nVerts = 0;
nTree = 0;
for (int j = 0; j < MAX_VERTS; j++) //set adjacency
for (int k = 0; k < MAX_VERTS; k++) //matrix
adjMat[j][k] = INFINITY; //to infinity
} //end constructor
public void addVertex( char lab)
{
vertexList[nVerts++] = new Vertex(lab);
}
... and the functions continue. I just need help with declaring and initialising in C++. Here is what I have in C++. I can't for the life of me get it to compile.
Code:
class Graph
{
public:
int MAX_VERTS; //Need to change later to match user input
int INFINITY;
Vertex vertexList[]; //list of all our vertices
int adjMat[][]; //This is our adjacency matrix for vertice layout representation
DistPar sPath[]; //shortest path array
int nTree; //Number of vertices in our tree
int nVerts; //current number of vertices
int currentVert; //current vertex
int startToCurrent; //distance to currentVert from start
Graph() //Needs to take input parameters later
{
MAX_VERTS = 999;
INFINITY = 1000000;
nVerts = 0;
nTree = 0;
vertexList = new Vertex[MAX_VERTS];
adjMat = new int[MAX_VERTS][MAX_VERTS];
//Set adjMatrix to infinity
for ( int a = 0; a < MAX_VERTS; a++)
for ( int b = 0; b < MAX_VERTS; b++)
adjMat[a][b] = INFINITY;
//Initialize sPath to all infinities
//sPath = new DistPar[MAX_VERTS];
}
void addVertex(char lab)
{
nVerts++;
vertexList[nVerts] = Vertex(lab);
}
I know it looks almost exactly the same as its java counterpart. I have several sources opened, but it's all bits and pieces of what I need. So I've decided to ask the community to point me in the right direction instead.