summaryrefslogtreecommitdiff
path: root/c/dataStructure/408/graph/graph.h
blob: 98b18bbbc54dfcf50a4fc17e5a9022f48d46903f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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