diff options
| author | garhve <git@garhve.com> | 2022-12-05 19:43:39 +0800 | 
|---|---|---|
| committer | garhve <git@garhve.com> | 2022-12-05 19:43:39 +0800 | 
| commit | c6bc541ab58363d783e60a007e80e9bf9e231fda (patch) | |
| tree | a59c7ed0d05225c5876f3e5e919d4f6ed0c447ff /c/dataStructure/408/graph/graph.h | |
initialize
Diffstat (limited to 'c/dataStructure/408/graph/graph.h')
| -rwxr-xr-x | c/dataStructure/408/graph/graph.h | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/c/dataStructure/408/graph/graph.h b/c/dataStructure/408/graph/graph.h new file mode 100755 index 0000000..98b18bb --- /dev/null +++ b/c/dataStructure/408/graph/graph.h @@ -0,0 +1,45 @@ +#ifndef _GRAPH_H +#define _GRAPH_H + +/* + * We can use this header for both + * directed graph or undirected graph + * by toggle boolean flag 'directed' + * in graph structure. + */ + +#include<stdio.h> +#include<stdbool.h> +#include<stdlib.h> +#include "queue/queue.h" + +#define MAXV 5  /* maximum number of vertices */ + +typedef struct edgenode { +    int y;      /* adjacency info */ +    int weight; /* edge weight if any */ +    struct edgenode * next;    /* next edge in list */ +} edgeNode; + +/* graph nodes start by 1 */ +typedef struct { +    edgeNode * edges[MAXV + 1];     /* adjacency info */ +    int degree[MAXV + 1];            /* outdegree of each vertex */ +    int nvertices;                  /* number of vertices in graph */ +    int nedges;                     /* number of edges in graph */ +    bool directed;                   /* is the graph directed? */ +    bool discovered[MAXV + 1]; +    bool processed[MAXV + 1]; +    int parent[MAXV + 1]; +} graph; + +void retreat         (char * str); +void initializeGraph(graph * g, bool directed); +void readGraph      (graph * g, bool directed); +void insertEdge     (graph * g, int x, int y, bool directed); +void printGraph     (graph * g); +void purgeGraph     (graph * g); +void initializeSearch(graph * g); +void bfs(graph * g, int start); + +#endif | 
