Main Page   Data Structures   File List   Data Fields   Globals  

bfs.h File Reference

Go to the source code of this file.

Data Structures

struct  graph
 The type of the graph. More...

struct  node
 The type of a graph node. More...


Typedefs

typedef node Node
 The type of a graph node. More...

typedef graph Graph
 The type of the graph. More...


Functions

int graph_init (Graph *graph, const char *file_name)
 Initializes a graph. More...

void graph_clear (Graph *graph)
 Clears a graph. More...

void BFS (Node *root)
 Implements the Breath-First-Search algorithm. More...

Nodeget_node_by_id (Graph *graph, unsigned int id)
 Obtains a graph node by its id. More...

void tree_print (Node *root)
 Prints a tree from root. More...

void exit_error (char *err_msg)
 Clears the resources and exists with an error code. More...

void print_help (char *prog_name)
 Prints a concise message describing the command line. More...

int get_line (FILE *stream, char *line, int size)
 Reads a line from the input stream. More...


Typedef Documentation

typedef struct graph Graph
 

The type of the graph.

typedef struct node Node
 

The type of a graph node.


Function Documentation

void BFS Node   root
 

Implements the Breath-First-Search algorithm.

void exit_error char *    err_msg
 

Clears the resources and exists with an error code.

int get_line FILE *    stream,
char *    line,
int    size
 

Reads a line from the input stream.

Node* get_node_by_id Graph   graph,
unsigned int    id
 

Obtains a graph node by its id.

Obtains a graph node by its id. If the id is invalid, generates an error

void graph_clear Graph   graph
 

Clears a graph.

Clears a graph Deallocates all data structures used by a graph

Parameters:
graph  the graph to be cleared

int graph_init Graph   graph,
const char *    file_name
 

Initializes a graph.

Reads a description of a graph from an input file and creates it. Allocates an array if nodes, and adds arcs as necessary.

Parameters:
graph  the output graph
file_name  the name of the input file that contains the graph description.
The file format follows. The number of nodes in the graph (must be greater than 0) followed by bi-directional arcs. An id of a node is a number from 0 to n-1. Each arc is described by a pair of nodes embeded within parenthesis and separated with a comma, for example (1, 2)

Returns:
0 upon success, and a negative number upon failure.
Possible errors: 1. The input file does not exist or it is not readable 2. The number of nodes is 0 3. An attempt to insert an arc that already exists. For example (a,b), (b,a) 4. An attempt to insert a self loops (a, a)

void print_help char *    prog_name
 

Prints a concise message describing the command line.

void tree_print Node   root
 

Prints a tree from root.


Generated on Mon May 10 18:07:26 2004 for BFS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002