-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
68 lines (64 loc) · 2.18 KB
/
main.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include "graph.h"
#include "dijkstra.h"
int main(int argc, char *argv[])
{
int no_vert,
i;
vrtx_node *listOfVertices,
*node,
*temp;
graph_p graph_instance;
/**
* Here we have initialized the 'arr[]' of all the nodes
* and the 'no_vert'. In improvement we have to remove
* this and replace it with dynamically fetched no_vert
* and Array Of Cities for us to find the minimum distance.
*/
char arr[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
no_vert = 8;
/**
* This for-block initializes all the vertices i.e.
* creates a list of all the vertices - listOfVertices. Can be improved
*/
for (i = 0; i < no_vert; i++) {
node = (vrtx_node *) malloc(sizeof(vrtx_node));
node->vertex = arr[i];
node->value = i;
node->next = NULL;
if (i == 0) {
temp = node;
listOfVertices = node;
} else {
temp->next = node;
temp = temp->next;
}
}
// Creating the graph with all the edges NULL
graph_instance = create_graph(no_vert);
// The list of vertices created - listOfVertices
// is later assigned to the graph_instance
graph_instance->vertices = listOfVertices;
// This adds SOURCE and DESTINATION to every edge
init_graph_edges(graph_instance);
add_edge(graph_instance, 'a', 'b', 9);
add_edge(graph_instance, 'a', 'f', 6);
add_edge(graph_instance, 'a', 'g', 13);
add_edge(graph_instance, 'b', 'c', 10);
add_edge(graph_instance, 'c', 'e', 6);
add_edge(graph_instance, 'c', 'h', 19);
add_edge(graph_instance, 'd', 'c', 6);
add_edge(graph_instance, 'd', 'h', 6);
add_edge(graph_instance, 'e', 'd', 11);
add_edge(graph_instance, 'e', 'h', 16);
add_edge(graph_instance, 'f', 'c', 18);
add_edge(graph_instance, 'f', 'e', 30);
add_edge(graph_instance, 'f', 'g', 8);
add_edge(graph_instance, 'g', 'e', 20);
add_edge(graph_instance, 'g', 'h', 25);
printGraph(graph_instance);
// Find the shortest path of the graph from the location 'a'
find_shortest_path(graph_instance, 'a');
return 0;
}