-
graph traversal
i need help writing a program that involves graph traversal... how do i read in the graph from a file whose name is specified on the command-line?
Also, how can i do the following?
1.) Ask the user what node to start at, and whether to perform breadth-first or depth-first traversal
2.) Put the graph-specific code into a library of graph-related functions (ie, like the Stack and Queue libraries).
thanks!
-
What have you come up with so far?
-Prelude
-
>how do i read in the graph from a file whose name is specified
>on the command-line?
Declare a pointer to FILE, then use fopen to open the file. Reading can be done by for example fgetc or fread.
>Ask the user what node to start at, and whether to perform
>breadth-first or depth-first traversal
You could use scanf to get the option from the user.
>Put the graph-specific code into a library of graph-related
>functions (ie, like the Stack and Queue libraries).
Use fputc, fwrite, something like that.