-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraph.h
45 lines (34 loc) · 1.17 KB
/
graph.h
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_
typedef enum {
UNDIRECTED = 0, DIRECTED
} graph_type_e;
/* Adjacency list node*/
typedef struct adjlist_node{
int vertex; /*Index of the vertex*/
adjlist_node *next; /*Pointer to the next node*/
} adjlist_node;
/* Adjacency list */
typedef struct {
int num_members; /*number of members in the list (for future use)*/
adjlist_node *head; /*head of the adjacency linked list*/
} adjlist;
/* Graph structure. A graph is an array of adjacency lists.
Size of array will be number of vertices in graph*/
typedef struct {
graph_type_e type; /*Directed or undirected graph */
int num_vertices; /*Number of vertices*/
adjlist *adjListArr; /*Adjacency lists' array*/
} graph;
adjlist_node* createNode(int v);
/* Function to create a graph with n vertices; Creates both directed and undirected graphs*/
graph* createGraph(int n, graph_type_e type);
/*Destroys the graph*/
void destroyGraph(graph *G);
/* Adds an edge to a graph*/
void addEdge(graph *G, int src, int dest);
/* Function to print the adjacency list of graph*/
void displayGraph(graph *G);
/* Return 1 if src is incident of dest */
int isIncident(graph *graph, int src, int dest);
#endif