Help with structures in a weighted graph

I have an assignment where I am given a weighted graph (vertices with lines connecting them, and the lines have a distance (the weight)). My assignment is to find the shortest path from any two vertices. My assignment is at the following link:

http://www.cs.ecu.edu/~karl/3300/fall15/Assignments/Assignment6/assn6.html

I do not need help with the entire thing, just on how to make the structures to fit the assignment... Here is what I have thus far, any suggestions/corrections? Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <cstdio>
#include <iostream>
#include "event.h"
#include "pqueue.h"
using namespace std;

struct AdjacencyList
{
	int vertex;
	double weight;
	AdjacencyList* next;

	AdjacencyList(int j, double w, AdjacencyList* n)
	{
		vertex = j;
		weight = w;
		next = n;
	}
};

struct VertexInfo
{
	AdjacencyList* list;
	int distance;
	int previous;

	VertexInfo(int d, int p)
	{

	}
};

struct Graph
{
	int numVerticies;
	int numEdges;
	VertexInfo vertices;

	Graph(int v, int e, VertexInfo verts)
	{
		numVerticies = v;
		numEdges = e;
		vertices = verts;
	}
};
Last edited on
It looks to me like your Graph contains only one vertex. You need a collection of VertexInfo's.

Why are you creating your own list for the adjacency list? Why not something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct Edge {
   int vertex;
   double weight;
   Edge(int v, weight = 0.0): vertex(v), weight(w) {}
};

struct Vertex {
    int distance;  // should this be a double?
    int previous;
    vector<Edge> edges;
    Vertex() : distance(0), previous(0) {}
};

struct Graph {
    vector<Vertex> vertices;
};



Topic archived. No new replies allowed.