Hello Id like someone to help me create these thanks 1 Type
Hello, I\'d like someone to help me create these, thanks!
1. Type Vertex
Create and document type Vertex. Each vertex v has the following pieces of information.
A pointer to a linked list of edges listing all edges that are incident on v. This list is called an adjacency list.
A real number indicating v\'s shortest distance from the start vertex. This number is 1 if the distance is not yet known.
A vertex number u. The shortest path from v to the start vertex begins by going from v to u. If the shortest path is not known, u is 1.
Create a constructor for type Vertex that takes no parameters and sets the vertex number and distance to 1 and the linked list to NULL.
2. Type Edge
Create and document type Edge. Type Edge is used for a cell in an adjacency list. The Edge structure stores three things.
A vertex number u.
A weight w.
A pointer next that points to the next Edge in the linked list.
Create a constructor that takes three parameters (a vertex number, a weight and a next pointer) and installs them into the three fields.
If a cell with vertex u and weight w occurs in the adjacency list for vertex v, then the graph has an edge from v to u of weight w.
3. Type Graph
Create and document type Graph. A graph stores the following.
The number of vertices.
The number of edges.
An array, vertices, where vertices[v] is a Vertex structure giving information about vertex v.
Create a contructor for Graph that takes a number of vertices as a parameter. It should allocate an array for the vertices and set the number of edges to 0. Notice that it is not necessary to have a maximum number of vertices. You allocate the array after you know how many vertices there are.
| 1. Type Vertex Create and document type Vertex. Each vertex v has the following pieces of information. A pointer to a linked list of edges listing all edges that are incident on v. This list is called an adjacency list. A real number indicating v\'s shortest distance from the start vertex. This number is 1 if the distance is not yet known. A vertex number u. The shortest path from v to the start vertex begins by going from v to u. If the shortest path is not known, u is 1. Create a constructor for type Vertex that takes no parameters and sets the vertex number and distance to 1 and the linked list to NULL. |
| 2. Type Edge Create and document type Edge. Type Edge is used for a cell in an adjacency list. The Edge structure stores three things. A vertex number u. A weight w. A pointer next that points to the next Edge in the linked list. Create a constructor that takes three parameters (a vertex number, a weight and a next pointer) and installs them into the three fields. If a cell with vertex u and weight w occurs in the adjacency list for vertex v, then the graph has an edge from v to u of weight w. Important note. An edge between u and v must occur in two adjacency lists, the list for u and the list for v, since it can be used to go from u to v or from v to u. |
| 3. Type Graph Create and document type Graph. A graph stores the following. The number of vertices. The number of edges. An array, vertices, where vertices[v] is a Vertex structure giving information about vertex v. Create a contructor for Graph that takes a number of vertices as a parameter. It should allocate an array for the vertices and set the number of edges to 0. Notice that it is not necessary to have a maximum number of vertices. You allocate the array after you know how many vertices there are. |
Solution
I am assuming from some terms in the question, that the problem needs to be done in C++. Following is the code:
#include <iostream>
using namespace std;
struct Edge{
int vertexNumber;
int weight;
struct Edge* next;
Edge( int vn, int wgt, struct Edge* nxt ){
vertexNumber = vn;
weight = wgt;
next = nxt;
};
};
struct Vertex{
struct Edge* adjacencyList;
double shortestDistance;
int vertexNumber;
Vertex(){
vertexNumber = shortestDistance = -1;
adjacencyList = NULL;
}
};
struct Graph{
int nVertices;
int nEdges;
struct Vertex* vertices;
Graph( int nVert ){
vertices = new struct Vertex[nVert];
nEdges = 0;
}
};
typedef struct Edge Edge;
typedef struct Vertex Vertex;
typedef struct Graph Graph;
int main(){
}


