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)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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)

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY