The input is in the following format.
5
1 2 9.0
1 3 12.0
2 4 18.0
2 3 6.0
2 5 20.0
3 5 15.0
0
1 5
The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. I can not figure out how to store the data into the List adjacency for each of the vertexes when reading it in. EX. Vertex 1 would have two List cells containing 2 9.0 and 3 12.0. I would also need to put the 1 9.0 and 1 12.0 into vertexes 2 and 3. But I can not figure out how to store the data into the ListCells
Code so Far:
#include <cstdio>
using namespace std;
typedef ListCell* List;
struct ListCell
{
ListCell* next;
int vertex;
double weight;
ListCell(int v, double w, ListCell* nxt)
{
vertex = v;
weight = w;
next = nxt;
}
};
struct Vertex
{
bool signaled;
long distance;
Vertex next;
List adjacency;
};
struct Graph
{
int numVertices;
Vertex* vertexInfo;
Graph(int n)
{
numVertices = n;
vertexInfo = new Vertex[n+1];
for(int i = 1; i <= n; i++)
{
vertexInfo[i].signaled = false;
}
}
};
//==============================================================
// readIn
//==============================================================
//
//==============================================================
void readIn()
{
int n, p1, p2;
double edge;
scanf("%i ", &n);
Graph(n);
while(scanf("%i " &p1) != 0)
{
}
}
Graphclass?