Using C Programming Add new vertex to DG Description The Adjacency List data structure for DG as follows: define MAXV 50 typedef struct _edgeNode { int adj; int w; _edgeNode *next; } EdgeNode; typedef struct _VertexNode{ char data[10]; EdgeNode *head; } VertexNode; typedef struct { VertexNode vertex[MAXV]; int vn,en; }AdjList; You are required to design a function like: void addVertex(AdjList G,char v[]); which add a new vertex(v) into the DG. if the vertex is already in the DG, do nothing, otherwise add it at end of vertex list. In order to test algorithm, you also need the following functions: void createAdjList(AdjList G); void OutputAdjList(AdjList G); int LocateVertex(AdjList G,char v[]); void Output(AdjList *G); Input first line enter 2 numbers for(nv,ne). second line enter the all vertex data (such A B C D…) start from third line, enter edge information,each edge is in form of v1 v2 w Where v1 is starting vertex and v2 is end vertex data, w is weight of the edge. separated by space. The last line enter a vertex (it is a string). Output The first line output the vertex number and edge number. The second line outputs all vertex data. starting from third line, print out edge data. each line for each vertex. In one line print out all out edges of this vertex. Each edge is print out in form (startvertex endvertex weight), separated by one space. there is no space between two edge data. If a vertex has no out-edge, don't print anything and no empty line for it. Examples input 6 9 A B C D E F A B 3 A C 3 B D 1 D A 2 C B 3 D C 5 C E 2 E D 4 D F 6 G output 7 9 A B C D E F G (A C 3)(A B 3) (B D 1) (C E 2)(C B 3) (D F 6)(D C 5)(D A 2) (E D 4)
Using C
Add new vertex to DG
Description
The Adjacency List data structure for DG as follows:
define MAXV 50
typedef struct _edgeNode { int adj;
int w;
_edgeNode *next;
} EdgeNode;
typedef struct _VertexNode{
char data[10];
EdgeNode *head;
} VertexNode;
typedef struct { VertexNode vertex[MAXV];
int vn,en;
}AdjList; You are required to design a function like: void addVertex(AdjList G,char v[]); which add a new vertex(v) into the DG. if the vertex is already in the DG, do nothing, otherwise add it at end of vertex list. In order to test
Input
first line enter 2 numbers for(nv,ne). second line enter the all vertex data (such A B C D…) start from third line, enter edge information,each edge is in form of v1 v2 w Where v1 is starting vertex and v2 is end vertex data, w is weight of the edge. separated by space. The last line enter a vertex (it is a string).
Output
The first line output the vertex number and edge number. The second line outputs all vertex data. starting from third line, print out edge data. each line for each vertex. In one line print out all out edges of this vertex.
Each edge is print out in form (startvertex endvertex weight), separated by one space. there is no space between two edge data.
If a vertex has no out-edge, don't print anything and no empty line for it.
Examples
input
6 9
A B C D E F
A B 3
A C 3
B D 1
D A 2
C B 3
D C 5
C E 2
E D 4
D F 6
G
output
7 9
A B C D E F G
(A C 3)(A B 3)
(B D 1)
(C E 2)(C B 3)
(D F 6)(D C 5)(D A 2)
(E D 4)
Step by step
Solved in 2 steps