Given a undirected graph, you are required to design function like int Distance(AdjMatrix *G, char v1[10),char v2[10]).

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Given a undirected graph, you are required to design function like int Distance(AdjMatrix *G, char v1[10),char v2[10]).

Post by answerhappygod »

Given A Undirected Graph You Are Required To Design Function Like Int Distance Adjmatrix G Char V1 10 Char V2 10 1
Given A Undirected Graph You Are Required To Design Function Like Int Distance Adjmatrix G Char V1 10 Char V2 10 1 (109.58 KiB) Viewed 24 times
Given a undirected graph, you are required to design function like int Distance(AdjMatrix *G, char v1[10),char v2[10]). which determine the short path between vertex v1 and v2 and return the length of the short path. if there is no path between them, return -1. where v1 and v2 are vertex data like "A" "B", OR "Shanghai","Beijing". This is preset code. You only need write Distance function and submit it. Here is the main function showing How to call Distance function and other functions. You are required to use Floyd Method. #include #include #include const int INF=9999999; #define MAXV 50 typedef struct { char vertex[MAXV][10]; int vn,en; int m[MAXV][MAXV]; }AdjMatrix; int LocateVertex(AdjMatrix *G,char V[10]); void InitGraph(AdjMatrix *G); void Create AdjMatrix(AdjMatrix *G); int Distance(AdjMatrix *G,char v1[],char v2[]); int main() { AdjMatrix G; Init Graph(&G); Create AdjMatrix(&G); char V1[10],v2[10]; scanf("%s %s", v1,v2); printf("%d\n",Distance(v1,v2)); return 0; } Input first line enter 2 numbers for(nv,ne). second line enter the all vertex data (such ABC 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. Last line enter the two vertex (it is in form of string) Output Ouput a number in line. It is length of the shortest path between these two vertex or -1.
input 4 6 6 ABCD A B 8 А с 3 D в 11 с в 3 DA 2 D C 7 А в output 6
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply