31 int main(
int argc,
char *argv[])
41 for (i = 0; i < 100; i ++) {
42 ptr[i] = (
int *)
get_mem(1,
sizeof(
int));
43 size +=
sizeof(*(ptr[i]));
45 printf(
"size of allocated memory = %lu\n" , size);
46 for (i = 0; i < 100; i++) {
102 for(i = 0; i < 10; i++) {
107 f= (float)i+0.222 / 2.0f;
118 for(i = 0; i < 4; i++) {
136 for(i = 4; i > 0; i--) {
140 f= (float)i+0.222 / 2.0f;
163 char c,*cp,*sp,str[][64] = {
"I",
"See",
"Everyting"};
190 for (i = 0; i < 3; i++) {
196 f= (float)i+0.222 / 2.0f;
211 tmp = l4->
find(l4,
"SEe");
213 printf(
"Data present \n");
216 printf(
"Data not present \n");
220 LOG_INFO(
"TEST",
"deleting nodes in link list\n");
221 for (i = 0; i < 3; i++) {
223 cp = l2->
del(l2, &c);
226 ip = l1->
del(l1, &i);
229 f= (float)i+0.222 / 2.0f;
230 fp = l3->
del(l3, &f);
233 sp = l4->
del(l4, &str[i]);
236 fp = l5->
del(l5, &f);
247 for (i = 0; i < 3; i++) {
253 f= (float)i+0.222 / 2.0f;
267 for (i = 3; i < 13; i++) {
273 f= (float)i+0.222 / 2.0f;
285 for (i = 2; i >= 0; i--) {
337 for(i = 0; i < 10; i++) {
341 f= (float)i+0.222 / 2.0f;
349 for(i = 0; i < 10; i++) {
360 for(i = 0; i < 4; i++) {
363 f= (float)i+0.222 / 2.0f;
373 fp = q2->
peek(q2, 2);
374 printf(
"peeking idx <2: %f>\n", *fp);
387 float f, arr1[10]={0};
388 int arr[10] = {1,53,32,43,3,23,11,209, -2, 25};
389 char carr[10] = {
'&',
'^',
'j',
'a',
'r',
'e',
'm',
'*',
'%',
'!'};
437 printf(
"Heapify'd array\n");
442 printf(
"%d\n", *(
int*)(h1->
extract(h1)));
443 printf(
"%d\n", *(
int*)(h1->
extract(h1)));
463 char c,*cp,str[][64] = {
"I",
"See",
"Everyting"};
464 char carr[10] = {
'&',
'^',
'j',
'a',
'r',
'e',
'm',
'*',
'%',
'!'};
469 t_tree *t1, *t2, *t3, *t4;
488 for(i = 0; i < 3; i++) {
491 f= (float)i+0.222 / 2.0f;
498 for(i = 9; i >= 3; i--) {
500 f= (float)i+0.222 / 2.0f;
506 char str1[10] =
"some";
507 if (t3->
find(t3, str1) == NULL) {
508 printf(
"%s not present in tree\n", str1);
510 printf(
"%s present in tree\n", str1);
515 if (t3->
find(t3, str2) == NULL) {
516 printf(
"%s not present in tree\n", str2);
518 printf(
"%s present in tree\n", str2);
522 printf(
"\nmin & max\n");
525 printf(
"%c %c\n", *(
char*) max->
key, *(
char*)min->
key);
529 printf(
"%f %f\n", *(
float*)max->
key,*(
float*)min->
key);
533 printf(
"%s %s\n", (
char*)max->
key, (
char*) min->
key);
536 printf(
"\nPred & Succ\n");
538 pred = t1->
pred(t1,&c);
539 succ = t1->
succ(t1,&c);
540 printf(
"%c %c\n", *(
char*) pred->
key, *(
char*)succ->
key);
543 pred = t2->
pred(t2,&f);
544 succ = t2->
succ(t2,&f);
545 printf(
"%f %f\n", *(
float*) pred->
key, *(
float*)succ->
key);
547 pred = t3->
pred(t3,str[0]);
548 succ = t3->
succ(t3,str[0]);
549 printf(
"%s %s\n", (
char*) pred->
key, (
char*)succ->
key);
554 printf(
"Tree height avl/bst %d %d\n",
581 for(i = 9; i >= 0; i--) {
582 cp = t1->
del(t1, &carr[i]);
584 f= (float)i+0.222 / 2.0f;
585 fp = t2->
del(t2, &f);
601 t_graph *g1, *g2, *g3, *g4, *g5;
602 char city[][64] ={
"Delhi",
"Bangalore",
"Chennai"};
603 int i, *ip, num[] = {1,2,3,4,5,6,7,8,9,10};
604 int a1[] = {1,2,3,4,5,6,7,8,9,10,11,12};
605 int a2[] = {1,2,3,4,5,6,7,8,9,10};
606 int a3[] = {1,2,3,4,5,6,7,8,9,10};
642 g1->
add_wedge(g1, city[2], city[0], 1000);
646 if (g1->
has_edge(g1, city[0], city[2]) == NULL) {
647 printf(
"%s not linked to %s\n",city[0],city[1]);
649 printf(
"%s linked to %s\n",city[0],city[1]);
663 if (g1->
find(g1, city[2]) == NULL) {
664 printf(
"%s not present in graph\n",city[2]);
666 printf(
"%s present in graph\n",city[2]);
671 printf(
"**************\n");
673 printf(
"- Connected Components -\n");
676 for (i = 0; i < 12; i++) {
698 bfs = g3->
bfs(g3, &a1[0]);
701 for(i = 0; i < 12; i++) {
702 ip = (
int*)bfs[i].parent;
703 printf(
"%d: %d %d %d\n",
704 bfs[i].comp,i+1, bfs[i].level, ip != NULL? *ip: -1);
710 dfs = g3->
dfs(g3, &a1[0]);
713 for(i = 0; i < 12; i++) {
714 ip = (
int*)dfs[i].parent;
715 printf(
"%d: %d %d {%d %d}\n",
716 dfs[i].comp, i+1, ip != NULL? *ip: -1, dfs[i].pre, dfs[i].post);
721 for (i = 0; i < 8; i++) {
739 printf(
"- DAGS Sorting and Longest Path -\n");
743 for(i = 0; i < 8; i++) {
744 ip = (
int*)dag[i].node;
746 ip != NULL? *ip: -1, dag[i].longest_path);
751 for (i = 0; i < 10; i++) {
767 printf(
"* Dijkstra's Algo *\n");
771 for (i = 0; i < 10; i++) {
772 printf(
"{%d : %d %d}\n",
780 printf(
"* Prim's Minimum Spanning Tree *\n");
784 for (i = 0; i < 10; i++) {
785 printf(
"{%d - %d: %d}\n",
793 printf(
"* Kruskal's Minimum Spanning Tree *\n");
797 for (i = 0; i < 10; i++) {
798 printf(
"{%d - %d: %d}\n",
807 for (i = 0; i < 10; i++) {
828 printf(
"* Bellman Ford *\n");
830 for (i = 0; i < 10; i++) {
831 printf(
"{%d : %d %d}\n",
852 int a1[] = {310,-22,35,534,55,76,907,8,239,1210,151,-12};
853 int a2[] = {310,-22,35,534,55,76,907,8,239,1210,151,-12};
854 int a3[] = {310,-22,35,534,55,76,907,8,239,1210,151,-12};
863 printf(
"Select sort: \n");
864 for (
int i = 0; i < 12; i++) {
865 printf(
"%d ", a1[i]);
872 printf(
"Insertion sort: \n");
873 for (
int i = 0; i < 12; i++) {
874 printf(
"%d ", a2[i]);
881 printf(
"quick sort: \n");
882 for (
int i = 0; i < 12; i++) {
883 printf(
"%d ", a3[i]);
899 printf(
"* Disjoint set operation test *\n");
914 printf(
"find 2: %d\n",d->
find(d, 2));
915 printf(
"find 1: %d\n",d->
find(d, 4));
916 printf(
"find 8: %d\n",d->
find(d, 8));
void insertion_sort(t_gen a, int n, t_dparams *op)
Insertion sort builds the final sorted array one item at a time. It has an O(n2) time complexity
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...
void selection_sort(t_gen a, int n, t_dparams *op)
Selection sort is an in-place comparison sorting algorithm. It has an O(n2) time complexity
Contains declations of array operations and structure.
Top level include containg common headers.
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.
void fault_manager_init(f_fault_handle h)
Handles signals and faults depending on type of fault/signal occured
t_gen assign_float(float)
t_gen assign_string(char *)
t_gen dijkstra(t_gen d, t_gen data)
Utils function used by quick sort for swapping graph edges
t_gen kruskals_mst(t_gen d)
Find the Minimum Spanning for weighted undirected graph Using Kruskal's Algorithm
t_gen create_graph(char *name, int size, t_dparams *prm)
Create an instance of graph
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.
@ eSINGLE_CIRCULAR_LINKLIST
Singly Circular Link list.
@ eDOUBLE_LINKLIST
Doubly Link list.
@ eDOUBLE_CIRCULAR_LINKLIST
Doubly Circular Link list.
@ eXOR_LINKLIST
Xor Link list.
@ eSINGLE_LINKLIST
Singly Link list
#define LOG_INFO(mod, fmt, args...)
#define LOG_TRACE_IN(mod, fmt, args...)
#define LOG_DEBUG(mod, fmt, args...)
#define LOG_TRACE_OUT(mod, fmt, args...)
#define LOG_ERROR(mod, fmt, args...)
void logger_init()
Initailize logger module
#define LOG_WARN(mod, fmt, args...)
void mem_init(void)
Initailize memory module
void mem_finit(void)
Close memory module by checking and destroying if any tagged memory
#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.
@ eARRAY_QUEUE_CIRC
Array 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.
@ eARRAY_STACK
Top Growing Stack.
@ eLL_STACK
LinkList based Stack.
@ eARRAY_STACK_DOWN
Down Growing Stack.
Level and Parent info after BFS walk.
Longest Path and Node order after DAG ordering.
f_free free
Routine used for freeing elements of said data.
Level and Parent info after DFS walk.
Disjoint set main struct definition.
f_print print
routine to print elements in the disjoint set
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.
int weight
Cost of the edge.
t_gnode * node
Pointer to neighbor vertex.
int idx
Index of vertex in adaceny list.
f_find find
routine to find a vertex 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
f_wedge add_wedge_sym
routine to add a weighted symmetric edge in graph
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
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
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
f_update update
routine to update a key of given heap node
f_ins insert
routine to insert elements in heap
f_vgen sort
routine to heap sort
f_print print
routine to print heap info
f_vgen build
routine to heapify
f_destroy destroy
routine to destroy
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_ins add
routine to Add elem at begin of link list
f_ins append
routine to Add elem at end of link list
f_print print
routine to print the link list
f_destroy destroy
routine destroy the link list instance
f_del_idx del_idx
routine to del node at idx
f_del del
routine to del node with matching elem of link list
f_vgen destroy
routine to destroy stack contents
f_print print
routine to print stack contents
f_gen2 push
stack operations
f_gen pop
routine to pop element into stack
f_print print
routine to print queue elements
f_gen deq
routine to pop elements out of queue
f_destroy destroy
routine to detroy queue instance
f_genidx peek
routine to peek node in queue
f_ins enq
routine to push elements to queue
t_gen key
Pointer to node key.
f_gen min
routine to get minm element in tree
f_find find
routine to find element in tree
f_len height
routine to get height of tree
f_gen2 pred
routine to get predecessor to given node
f_ins insert
routine to insert element in tree
f_print print
routine to print tree level by level
f_print inorder
routine to print inorder traversal of tree
f_gen max
routine to get maxm element in tree
f_destroy destroy
routine to destroy the tree instance
f_print preorder
routine to print preorder traversal of tree
t_gen root
Root node of the tree.
f_gen2 succ
routine to get successor to given node
f_del del
routine to delete element in tree
f_print postorder
routine to print postorder traversal of tree
void test_array()
Test Array search and sort routines
void test_tree()
Test Tree routines
int main(int argc, char *argv[])
Main Driver test
void test_heap()
Test Heap routines
void test_graph()
Test Graph routines
void test_linklist()
Test link list routines
void test_queue()
Test Queue routines
void test_stack()
Test stack routines
void test_disjoint_set()
Test Disjoint set routines (Merge-Find)
t_gen create_tree(char *name, e_treetype ttype, t_dparams *prm)
Create an instance of tree
Contains declations of tree types, operations and structure.
@ eBST
Binary Search Tree.
void * t_gen
Base Data type used for all data structure and data elements.