Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please correct my code where is it wrong: #include #include #include #include #include #define MAX _ NODES 1 0 0 #define NAME _ MAX 1
Please correct my code where is it wrong:
#include
#include
#include
#include
#include
#define MAXNODES
#define NAMEMAX
typedef struct
char NodeNAMEMAX;
char NodeNAMEMAX;
int load;
Links;
typedef struct
Links linksMAXNODES;
int numlinks;
Diagram;
void InsertNewDiagramDiagram diagram;
void saveNewDiagram diagram;
void SelectDiagram;
void ShortPathDiagram diagram;
int main
int options;
Diagram diagram;
diagram.numlinks ;
do
printf
Menu Options:
;
printfOption : Insert a new graph.
;
printfOption : Choose a graph from the CSV files to activate.
;
printfOption : Find the shortest path of the active graph.
;
printfOption : Exit the program.
;
printf
Provide the option you want to choose: ;
scanfd &options;
switch options
case :
InsertNewDiagram&diagram;
break;
case :
SelectDiagram;
break;
case :
if diagramnumlinks
printfNo Graph selected. Firstly select a Graph.
;
else
ShortPath&diagram;
break;
case :
printfLeave the program.
;
break;
default:
printfIncorrect option chosen. Retry.
;
while options ;
return ;
Option
void InsertNewDiagramDiagram diagram
char NodeNAMEMAX NodeNAMEMAX;
int load, numlinks;
printfProvide the amount of Edges the graph has: ;
scanfd &numlinks;
diagramnumlinks numlinks;
printfProvide the vertices in capital letters and weight:
;
printfVertexVertexWeight
;
for int i ; i numlinks; i
scanfssd Node Node &load;
strcpydiagramlinksiNode Node;
strcpydiagramlinksiNode Node;
diagramlinksiload load;
saveNewdiagram;
void saveNewDiagram diagram
char NameNAMEMAX;
FILE fp;
printfProvide the name you want to save the graph to: ;
scanfs Name;
fp fopenNamew;
if fp NULL
printfThe file cannot be opened
;
return;
for int i ; i diagramnumlinks; i
fprintffpssd
diagramlinksiNode diagramlinksiNode diagramlinksiload;
fclosefp;
printfThe Graph is saved under s
Name;
Option
void SelectDiagram
DIR dir;
struct dirent entry;
char rentNameNAMEMAX;
printfProvide the path to the location of the CSV files: ;
scanfs rentName;
if dir opendirrentName NULL
int compute ;
char filesNAMEMAX;
while entry readdirdir NULL
if strstrentrydname, csv NULL
strcpyfilescompute entrydname;
compute;
closedirdir;
if compute
printfThere are no CSV files available to use.
;
return;
printfThe available CSV files:
;
for int i ; i compute; i
printfds
i filesi;
int choose;
printfProvide the number of the file to be added: ;
scanfd &choose;
if choose choose compute
printfIncorrect option chosen.
;
return;
printfThe option you chose is: s
fileschoose ;
else
perrorError in openening directory.";
finding index of vertices
int discoverINDchar apex Diagram diagram
for int j ; j diagramnumlinks; j
if strcmpdiagramlinksjNode apex strcmpdiagramlinksjNode apex
return j;
return ;
Dijkstra
void DijkstraDiagram diagram char begin char fin
int c diagramnumlinks;
int spanMAXNODES;
int beforeMAXNODES;
int markedMAXNODES;
for int k ; k c; k
spank INTMAX;
beforek;
markedk; Initialize marked array with zeroes
int beginIND discoverINDbegin diagram;
int finIND discoverINDfin diagram;
if beginIND finIND
printfUnable to find the startpoint or endpoint of the vertex given in Graph.
;
return;
spanbeginIND;
The algorithm itself
for int sum ; sum c ; sum
int shortestSpan INTMAX;
int shortestIND ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started