103 for (i = 0; i < g->
count; i++) {
123 if (neighl->
node == node) {
160 node = g->
find(g, data);
204 if (A == NULL || B == NULL) {
230 if (A == NULL || B == NULL) {
235 if (g->
has_edge(g, n1, n2) != NULL) {
270 if (A == NULL || B == NULL) {
275 if (g->
has_edge(g, n1, n2) != NULL) {
307 if (A == NULL || B == NULL) {
402 for (i = 0; i < g->
count; i++) {
447 while (q->
empty(q) !=
true) {
454 end = neigh_list->
end_node(neigh_list);
466 cur = neigh_list->
next_node(neigh_list, cur);
493 bool all_nodes_visited =
false;
496 node = g->
find(g, n);
510 for (
int i = 0; i < g->
count; i++) {
517 while (all_nodes_visited ==
false) {
520 all_nodes_visited =
true;
522 for (
int i = 0; i < g->
count; i++) {
525 if (bfs[i].level == -1) {
526 all_nodes_visited =
false;
559 dfs[node->
idx].
pre = count++;
565 end = neigh_list->
end_node(neigh_list);
574 if (dfs[neigh->
idx].
pre == -1) {
576 dfs[neigh->
idx].
pre = count++;
585 cur = neigh_list->
next_node(neigh_list, cur);
605 }
while (s->
empty(s) !=
true);
630 bool all_nodes_visited =
false;
633 node = g->
find(g, n);
647 for (
int i = 0; i < g->
count; i++) {
656 while (all_nodes_visited ==
false) {
657 dfs_core(g, node, dfs, s, comp, &count);
659 all_nodes_visited =
true;
660 for (
int i = 0; i < g->
count; i++) {
663 if (dfs[i].pre == -1) {
664 all_nodes_visited =
false;
698 node = g->
find(g, n);
712 for (
int i = 0; i < g->
count; i++) {
719 dfs[node->
idx].
pre = count++;
734 if (dfs[neigh->
idx].
pre == -1) {
737 dfs[neigh->
idx].
pre = count++;
745 edge = neigh_list->
del_idx(neigh_list, 0);
746 neigh_list->
append(neigh_list, edge);
752 cur = neigh_list->
next_node(neigh_list, cur);
772 }
while (s->
empty(s) !=
true);
807 for (
int i = 0; i < g->
count; i++) {
813 for (
int i = 0; i < g->
count; i++) {
816 end = neigh_list->
end_node(neigh_list);
821 cur = neigh_list->
next_node(neigh_list, cur);
829 for (
int i = 0; i < g->
count; i++) {
830 if (dag_inf[i].indegree == 0) {
837 while (q->
empty(q) !=
true) {
845 neigh_list = node->
neigh;
847 end = neigh_list->
end_node(neigh_list);
862 cur = neigh_list->
next_node(neigh_list, cur);
915 for (i = 0; i < g->
count; i++) {
944 printf(
" %d> ", edge->
weight);
966 for (i = 0; i < g->
count; i++) {
1057 node = g->
find(g, data);
1077 for (
int i = 0; i < g->
count; i++) {
1088 while (h->
empty(h) !=
true) {
1095 cur = neigh_list->
head_node(neigh_list);
1096 end = neigh_list->
end_node(neigh_list);
1111 cur = neigh_list->
next_node(neigh_list, cur);
1149 node = g->
find(g, data);
1161 for (
int i = 0; i < g->
count; i++) {
1171 in_q[node->
idx] =
true;
1172 while (q->
empty(q) !=
true) {
1176 cur = neigh_list->
head_node(neigh_list);
1177 end = neigh_list->
end_node(neigh_list);
1189 if (in_q[v->
node->
idx] !=
true) {
1197 cur = neigh_list->
next_node(neigh_list, cur);
1243 for (
int i = 0; i < g->
count; i++) {
1251 h->
insert(h, &dist[0].edge);
1252 while (h->
empty(h) !=
true) {
1258 cur = neigh_list->
head_node(neigh_list);
1259 end = neigh_list->
end_node(neigh_list);
1274 cur = neigh_list->
next_node(neigh_list, cur);
1314 for (j = i = 0; i < g->
count; i++) {
1316 cur = neigh_list->
head_node(neigh_list);
1317 end = neigh_list->
end_node(neigh_list);
1323 cur = neigh_list->
next_node(neigh_list, cur);
1333 dp.
swap_idx = graph_wedge_swap_idx;
1345 for (j = i = 0; (j < g->
count) && (i < g->total_edges); i++) {
1374 for (i = 0; i < g->
count; i++) {
void quick_sort(t_gen a, int n, t_dparams *op)
Quicksort is an in-place sorting algorithm is a divide and conquer algorithm which relies on a partit...
Contains declations of array operations and structure.
void init_data_params(t_dparams *, e_data_types)
Called to initalize data params for default data types Else for custom data types the data params str...
void dummy_free(void *mem_addr, char *file, int line)
Dummy free function Else for custom data types the data params structure is to be defined by user
t_gen create_disjoint_set(char *name, int size)
Create an instance of disjoint set data struct
Contains declations of disjoint_set types, operations and structure.
t_gen gen_get_idx(t_gen x, int idx1)
void gen_swp_idx(t_gen x, int idx1, int idx2)
void gen_cpy_idx(t_gen x, int idx1, t_gen data)
#define SWP_IDX(T, NAME)
Template function for swaping elemts at given indicies of an array for default data types.
t_gen graph_add_edge(t_gen d, t_gen n1, t_gen n2)
Add an asymmetric edge between two vertices(nodes) in graph;
void graph_wneigh_print(t_gen d, t_gen neigh)
Util function to Print neighbor list of a vetex(node) with edge weights
void graph_neigh_print(t_gen d, t_gen neigh)
Util function to Print neighbor list of a vetex(node)
void graph_neigh_list_free(t_gen mem, char *file, int line)
Util free function for deleting neigh link list node data
t_gen graph_del_vertex(t_gen d, t_gen n1)
Del a vertex(node) in graph;
t_gen graph_toplogicaly_order_dag(t_gen d)
Topologicaly order/Topologicaly sort the nodes of a DAG And get the longest path to each of the verti...
e_cmpr graph_wedge_cmpr_idx2(t_gen x, int i, int j)
Utils function used by quick sort for comparing graph edge weights
t_gen graph_add_wedge_sym(t_gen d, t_gen n1, t_gen n2, int weight)
Add a symmetric weighted edge between two vertices(nodes) in graph;
void graph_wprint(t_gen d)
Print Graph info with edge weights
t_gen graph_has_edge(t_gen d, t_gen n1, t_gen n2)
Check edge between two Vertices(nodes) in graph;
t_gen graph_add_edge_sym(t_gen d, t_gen n1, t_gen n2)
Add a symmetric edge between two vertices(nodes) in graph;
t_gen graph_dfs(t_gen d, t_gen n)
Depth First Search DFS info contains
e_cmpr graph_wedge_cmpr_idx(t_gen x, int i, int j)
Utils function used by genric heap for comparing graph edge weights
t_gen dijkstra(t_gen d, t_gen data)
Utils function used by quick sort for swapping graph edges
t_gen graph_del_edge(t_gen d, t_gen n1, t_gen n2)
Del an asymmetric edge between two vertices(nodes) in graph;
t_gen graph_delete(t_gen, t_gen)
t_gen graph_bfs(t_gen d, t_gen n)
Breath First Search BFS info Contains
void graph_print(t_gen d)
Print Graph info
e_cmpr graph_wedge_cmpr(t_gen x, t_gen y)
Utils function used for comparing two different graph edges
t_gen kruskals_mst(t_gen d)
Find the Minimum Spanning for weighted undirected graph Using Kruskal's Algorithm
t_gen graph_del_edge_sym(t_gen d, t_gen n1, t_gen n2)
Del a symmetric edge between two vertices(nodes) in graph;
t_gen graph_find(t_gen, t_gen)
Find a Vertex(node) in graph;
t_gen graph_add_wedge(t_gen d, t_gen n1, t_gen n2, int weight)
Add an asymmetric weighted edge between two vertices(nodes) in graph;
void bfs_core(t_graph *g, t_gnode *node, t_bfsinfo *bfs, t_queue *q, int comp)
Breath First Search Core routine This routine does bfs on all conncted components
void graph_destroy(t_gen d)
Destroy instance of graph
void dfs_core(t_graph *g, t_gnode *node, t_dfsinfo *dfs, t_stack *s, int comp, int *gcount)
Depth First Search Core routine This routine does dfs on all conncted components
t_gen create_graph(char *name, int size, t_dparams *prm)
Create an instance of graph
int graph_len(t_gen)
get num Vertex(nodes) in graph;
t_gen graph_add_vertex(t_gen d, t_gen data)
Add a Vertex(node) in graph;
t_gen graph_dfs_optimised(t_gen d, t_gen n)
Depth First Search Optimised by eliminating the need for revisiting a previously visited vetex in nei...
e_cmpr graph_neigh_list_compare(t_gen x, t_gen y)
Util compare function for neigh link list node data
t_gen prims_mst(t_gen d)
Find the Minimum Spanning for weighted undirected graph Using Prim's Algorithm
t_gen bellman_ford(t_gen d, t_gen data)
Find the shortest path from a given source vertex to all source nodes in a graph with negative edges ...
Contains declations of graph types, operations and structure.
t_gen create_heap(char *name, t_gen data, int size, e_heaptype htype, t_dparams *prm)
Create an instance of heap
Contains declations of heap types, operations and structure.
t_gen create_link_list(char *name, e_lltype type, t_dparams *prm)
Create an instance of link list
Contains declations of link list types, node and link list structure.
@ eXOR_LINKLIST
Xor Link list.
#define free_mem(mem_addr)
#define get_mem(nmemb, size)
t_gen create_queue(char *name, int max_size, e_queuetype qtype, t_dparams *prm)
Destroy queue instance
Contains declations of queue types, operations and structure.
@ eLL_QUEUE_CIRC
Link List Based Queue.
t_gen create_stack(char *name, int max_size, e_stacktype stype, t_dparams *prm)
Create an instance of stack
Contains declations of stack types, operations and structure.
@ eLL_STACK
LinkList based Stack.
Level and Parent info after BFS walk.
t_gen parent
Pointer to Parent Vertex.
int comp
Subgraph id of vertex.
int level
Level of vertex from the source.
Longest Path and Node order after DAG ordering.
int indegree
Used internally for topologicaly order and find longest path in DAG.
int longest_path
Longest path to vertex in DAG.
t_gen node
Pointer to Vertex in topologically sorted order.
f_cmpr cmpr
Routine used for comparing two given elems of said type.
f_get_idx get_idx
Routine used for getting elem in given array index.
f_swap swap
Routine used for swaping two elemnts of goven data.
f_swp_idx swap_idx
Routine used for swapring elems in given array indicies.
f_free free
Routine used for freeing elements of said data.
f_cpy_idx copy_idx
Routine used for copying elems in given array indicies.
f_print print_data
Routine used for printing elem data.
f_cmp_idx cmpr_idx
Routine used for comparing elems in given array indicies.
Level and Parent info after DFS walk.
t_gen parent
Pointer to Parent Vertex.
int post
Post Interval of a vertex on dfs walk.
int comp
Subgraph id of vertex.
int visited_neighbors
Used internally Flag indicating neighbors still to be visited.
int pre
Pre Interval of a vertex on dfs walk.
Disjoint set main struct definition.
f_set2 merge
routine to merge to set
f_destroy destroy
routine to destroy the instace of disjoint set
f_set1 find
routine to find an elem in the set
f_vgen make
routine to add an new elem to the set
t_gnode * parent
Pointer to Vertex vertex.
t_gedge edge
Pointer to edge.
graph neighbor edges represented in neigh list
int weight
Cost of the edge.
t_gnode * node
Pointer to neighbor vertex.
t_linklist * neigh
Link List to neighbor vertices(nodes)
t_gen id
Pointer to store Data.
int idx
Index of vertex in adaceny list.
f_find find
routine to find a vertex in graph
f_len len
routine to get vertex count in graph
f_print wprint
routine to print graph info with edge weights
f_gen3 del_edge_sym
routine to del a symmetric edge in graph
f_print print
routine to print graph info
t_gnode * nodes
Adaceny List Representation of graph vertices.
f_wedge add_wedge_sym
routine to add a weighted symmetric edge in graph
char * name
Graph Instance Name.
f_destroy destroy
routine to destroy the graph instance
f_gen3 add_edge_sym
routine to add a symmetric edge in graph
f_gen3 del_edge
routine to del an edge in graph
f_gen3 has_edge
routine to check an edge between two vertices graph
f_gen3 add_edge
routine to add an edge in graph
int max_size
Max Vertex count of graph.
f_wedge add_wedge
routine to add a weighted edge in graph
f_gen2 bfs
routine to Breadth First Search in graph
f_gen2 del_vertex
routine to del a vertex in graph
int count
Vertex Count of graph.
f_gen2 dfs
routine to Depth First Search in graph
f_gen topo_order_dag
routine to topologica order a DAG
f_gen2 add_vertex
routine to add a vertex in graph
int total_edges
Edge count of graph.
f_ins insert
routine to insert elements in heap
f_destroy destroy
routine to destroy
f_empty empty
routine to check if heap empty
f_gen extract
routine to extract min/max root element in heap
Link List main structure.
f_find find
routine to find and get the node with matching elem
f_gen2 next_node
routine to get the next node of the given node
f_len len
routine to get len of link list
f_ins append
routine to Add elem at end of link list
f_destroy destroy
routine destroy the link list instance
f_gen head_node
routine to get the head node
f_del_idx del_idx
routine to del node at idx
f_gen end_node
routine to get the end node
f_del del
routine to del node with matching elem of link list
Link list node definition.
t_gen data
Pointer to the data to be stored in link list.
f_vgen destroy
routine to destroy stack contents
f_gen2 push
stack operations
f_empty empty
routine to check if stack is empty
f_gen pop
routine to pop element into stack
f_gen deq
routine to pop elements out of queue
f_destroy destroy
routine to detroy queue instance
f_empty empty
routine to check if queue empty
f_ins enq
routine to push elements to queue
void * t_gen
Base Data type used for all data structure and data elements.
e_cmpr
Custom Compare function return type.