This is a homework problem; however I just want some direction. I have to write a module graph.cpp that implements djikstra's algorithm. so far i am at the reading in module and am trying to make an array of structures. here is the code.
// Zachary Dain
// CSCI 3300 Assignment 3
// tab stops: every 2 spaces
#include <iostream>
#include <math.h>
using namespace std;
enum StatusType {Done, Pending, Peripheral};
struct ListCell
{
ListCell* next;
int adjVertex;
double weight;
ListCell(int v, double wt, ListCell* n)
{
adjVertex = v;
weight = wt;
next = n;
}
};
struct arrayOfStructs
{
StatusType s;
ListCell* cell;
arrayOfStructs()
{
s = Pending;
cell = NULL;
}
};
// readGraph() reads in the graph and puts the
// values into the appropriate lists/PQ
void readGraph(int n)
{
int firstVert, secondVert;
double weight;
arrayOfStructs[] j = new arrayOfStructs[n+1];
while(firstVert != 0)
{
cin >> firstVert;
if(firstVert != 0)
{
cin >> secondVert;
cin >> weight;
j[firstVert].cell = new ListCell(secondVert,weight, j[firstVert].cell);
j[secondVert].cell = new ListCell(firstVert,weight, j[secondVert].cell);
}
}
}
int main()
{
int numVertex;
cin >> numVertex;
readGraph(numVertex);
}
I am getting the following errors:
graph.cpp: In function ‘void readGraph(int)’:
graph.cpp:43: error: expected unqualified-id before ‘[’ token
graph.cpp:51: error: ‘j’ was not declared in this scope
make: *** [graph] Error 1
I understand that the second error is due to the first one. I have looked around and have found no solution. Any advice? Should i use a typedef?